ast: enforce integer string limits in AST-only parsing - #8454
Conversation
Validate decimal integer literals from the parser token stream before lowering the parsed AST. Reuse the validator for normal compilation and the `_ast` parsing path so `PyCF_ONLY_AST`, `ast.parse()`, and `ast.literal_eval()` honor `int_max_str_digits` consistently. Remove the now-passing `test_literal_eval_str_int_limit` expected-failure marker. The token-based validator excludes non-decimal integers, floats, complex literals, strings, and comments without duplicating lexer logic. Assisted-by: Codex:gpt-5.6-sol
|
No actionable comments were generated in the recent review. 🎉 ℹ️ Recent review info⚙️ Run configurationConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro Plus Run ID: ⛔ Files ignored due to path filters (1)
📒 Files selected for processing (2)
📝 WalkthroughWalkthroughThe decimal integer literal length check moves from manual source-text scanning to token-based validation in the compiler crate, returning a ChangesDecimal Integer Digit Limit Enforcement
Estimated code review effort: 3 (Moderate) | ~25 minutes Suggested reviewers: 🚥 Pre-merge checks | ✅ 5✅ Passed checks (5 passed)
✨ Finishing Touches🧪 Generate unit tests (beta)
Thanks for using CodeRabbit! It's free for OSS, and your support helps us grow. If you like it, consider giving us a shout-out. Comment |
📦 Library DependenciesThe following Lib/ modules were modified. Here are their dependencies: [x] lib: cpython/Lib/ast.py dependencies:
dependent tests: (149 tests)
Legend:
|
Validate decimal integer literals from the parser token stream before lowering the parsed AST. Reuse the validator for normal compilation and the `_ast` parsing path so `PyCF_ONLY_AST`, `ast.parse()`, and `ast.literal_eval()` honor `int_max_str_digits` consistently. Remove the now-passing `test_literal_eval_str_int_limit` expected-failure marker. The token-based validator excludes non-decimal integers, floats, complex literals, strings, and comments without duplicating lexer logic. Assisted-by: Codex:gpt-5.6-sol
Summary
Enforce
int_max_str_digitsfor decimal integer literals parsed throughAST-only paths, including
PyCF_ONLY_AST,ast.parse(), andast.literal_eval().Details
Move the decimal-integer limit check from a manual source scan to the parser
token stream. Reuse it for normal compilation and
_astparsing, which keepsthe behavior consistent without duplicating lexer logic. The token-based check
excludes strings, comments, floats, complex literals, and non-decimal integer
literals.
The existing
test_literal_eval_str_int_limittest now passes, so remove itsexpectedFailuremarker.Testing
bash temp/ast/before-commit.shcompleted successfully:uv tool run prek run --all-filescargo fmt --checkcargo run --release Lib/test/test_ast/test_ast.pycargo run --release Lib/test/test_compile.pycargo run --release -- -m test test_compilecargo run --release -- -m test test_astcargo run -- extra_tests/snippets/stdlib_ast.pycargo run -- extra_tests/snippets/builtin_compile.pycargo clippy -p rustpython-compiler -p rustpython-vm -p rustpython-stdlib --all-targetsWorkspace test command
rustpython-capiis tested separately in CI and is excluded from this localworkspace command.
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