{{ message }}
ast: match CPython argument validation order - #8414
Merged
youknowone merged 1 commit intoJul 30, 2026
Merged
Conversation
Validate parameter annotations while converting ast.arguments, before merging positional and keyword-only defaults. This gives invalid annotation contexts precedence over default-list shape errors, as in CPython. Merge positional defaults before keyword-only defaults so an excess positional-default error also takes precedence over a keyword-only default length mismatch. Remove the expected-failure markers from the FunctionDef and Lambda AST validator tests that now pass. Assisted-by: Codex:gpt-5.6-sol
Contributor
Contributor
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.

Summary
Match CPython's
ast.argumentsvalidation order when compiling a Python ASTobject.
RustPython previously merged keyword-only defaults before validating parameter
annotations. Consequently, an invalid
Storecontext in an annotation couldbe hidden by a
kw_defaultslength error. It also reported that keyword-onlylength error before an excess positional-default error.
Validate parameter annotations before either default-list merge, then merge
positional defaults before keyword-only defaults. This preserves the existing
validation rule while giving errors the same precedence as CPython.
Remove the
expectedFailuremarkers from the FunctionDef and Lambda ASTvalidator tests, which now pass without changing their assertions or data.
Testing
uv tool run prek run --all-filescargo fmt --checkcargo run --release Lib/test/test_ast/test_ast.pycargo run --release -- -m test test_astcargo run -- extra_tests/snippets/stdlib_ast.pycargo clippy -p rustpython-stdlib --all-targetsWorkspace test command
rustpython-capiis tested separately in CI; its test binary previously couldnot load
libpython3.14.so.1.0in this local environment.rustpython-compiler-sourceis deprecated and is excluded from CI workspacebuilds as well.
cargo test --workspace \ --exclude rustpython-capi \ --exclude rustpython_wasm \ --exclude rustpython-compiler-source \ --exclude rustpython-venvlauncher \ --features threading \ -- --quietAI assistance: Codex:gpt-5.6-sol
Summary by CodeRabbit