Repository navigation
PEP 671: implement experimental late-bound argument defaults - #159455
Draft
yotatameguchi-boop wants to merge 1 commit into
Draft
yotatameguchi-boop wants to merge 1 commit into
yotatameguchi-boop wants to merge 1 commit into
Conversation
|
The following commit authors need to sign the Contributor License Agreement: |
|
Most changes to Python require a NEWS entry. Add one using the blurb_it web app or the blurb command-line tool. If this change has little impact on Python users, wait for a maintainer to apply the |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
This implements
name=>expressiondefaults from draft PEP 671 on current CPython main. An omitted argument evaluates its expression in the function's runtime scope; an explicitly supplied argument suppresses evaluation, includingNoneandEllipsis.This is an experimental reference implementation for evaluating the proposal. PEP 671 remains Draft; this change does not represent acceptance of the language proposal. The original reference implementation informed the design, but the implementation targets the current compiler, stack-reference interpreter, and function attribute machinery.
The change supports positional-only, positional-or-keyword, and keyword-only defaults; functions, lambdas, methods, generic functions, coroutines, generators, and captured parameters. It preserves left-to-right evaluation, original normalized expression descriptions before constant folding, and argument validation before evaluating defaults. It adds
QUERY_FAST/QUERY_DEREF, function metadata in__defaults_extra__/__kwdefaults_extra__, AST round-tripping, and signature rendering throughinspect.Parameter.late_default.FullArgSpecretains its seven-field shape.Validation on Apple Silicon macOS with Apple Clang 21, debug builds:
test_sys(105 tests);test_capi(1,611 tests). All test runs succeeded, with platform/resource skips.-X gil=0: 1,397 tests across 12 relevant modules; all test runs succeeded, with skips. Verifiedsys._is_gil_enabled()isFalse.test_late_defaults -R 3:3succeeded with no leaks during the measured repetitions.git diff --checksucceeded.Implementation limits: functions with late-bound defaults currently bypass existing call specializations and conservatively treat all parameters as potentially unbound for local-variable analysis. Two metadata pointers are added to every function object. The internal function layout and bytecode magic change. No public C API entry points are added. Windows/Linux, JIT-enabled execution, performance benchmarks, and a Sphinx documentation build have not been validated.
AI assistance was used for source investigation, implementation, documentation, and tests. The human contributor has confirmed review of the implementation and this description in accordance with CPython's AI tooling policy.
A matching upstream tracking issue has not been established. This draft is submitted as an experimental implementation of PEP 671 for discussion, not as an accepted language change.