ast: match CPython argument validation order by widehyo1 · Pull Request #8414 · RustPython/RustPython · GitHub
Skip to content

ast: match CPython argument validation order - #8414

Merged
youknowone merged 1 commit into
RustPython:mainfrom
widehyo1:fix-ast-arguments-validation-order
Jul 30, 2026
Merged

youknowone merged 1 commit into
RustPython:mainfrom
widehyo1:fix-ast-arguments-validation-order

Conversation

@widehyo1

@widehyo1 widehyo1 commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

Summary

Match CPython's ast.arguments validation order when compiling a Python AST
object.

RustPython previously merged keyword-only defaults before validating parameter
annotations. Consequently, an invalid Store context in an annotation could
be hidden by a kw_defaults length error. It also reported that keyword-only
length 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 expectedFailure markers from the FunctionDef and Lambda AST
validator tests, which now pass without changing their assertions or data.

Testing

  • uv tool run prek run --all-files
  • cargo fmt --check
  • cargo run --release Lib/test/test_ast/test_ast.py
    • 227 tests run
    • 7 skipped
    • 19 expected failures
  • cargo run --release -- -m test test_ast
  • cargo run -- extra_tests/snippets/stdlib_ast.py
  • cargo clippy -p rustpython-stdlib --all-targets
  • the configured workspace test suite
Workspace test command

rustpython-capi is tested separately in CI; its test binary previously could
not load libpython3.14.so.1.0 in this local environment.
rustpython-compiler-source is deprecated and is excluded from CI workspace
builds as well.

cargo test --workspace \
    --exclude rustpython-capi \
    --exclude rustpython_wasm \
    --exclude rustpython-compiler-source \
    --exclude rustpython-venvlauncher \
    --features threading \
    -- --quiet

AI assistance: Codex:gpt-5.6-sol

Summary by CodeRabbit

  • Bug Fixes
    • Improved validation of annotations across positional, variadic, keyword-only, and keyword parameters.
    • Validation errors are now reported before parameter defaults are merged, improving consistency for invalid function definitions.

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
@coderabbitai

coderabbitai Bot commented Jul 30, 2026

Copy link
Copy Markdown
Contributor

@github-actions

Copy link
Copy Markdown
Contributor

@youknowone youknowone left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

@youknowone
youknowone merged commit 55b3d68 into RustPython:main Jul 30, 2026
27 checks passed
@widehyo1
widehyo1 deleted the fix-ast-arguments-validation-order branch August 1, 2026 02:51
@moreal moreal added the z-ca-2026 Tag to track Contribution Academy 2026 label Aug 1, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

z-ca-2026 Tag to track Contribution Academy 2026

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants