You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
The AST schema adds ConstantValue, ExprConstant, and runtime_* storage across statements, expressions, patterns, and modules. Parsers initialize the new fields, and visitors, helpers, precedence, relocation, and comparable-node code add handling for Expr::Constant.
Changes
Constant AST runtime support
Layer / File(s)
Summary
AST field contracts crates/ruff_python_ast/ast.toml, crates/ruff_python_ast/src/nodes.rs, crates/ruff_python_ast/generate.py, crates/ruff_python_ast/src/generated.rs
ConstantValue and the new runtime_* fields are declared across AST schema and generated node structs, and the generator prefix list is extended for ConstantValue.
ExprConstant is wired through the generated expression wrappers, refs, node kinds, accessors, and root-node conversion APIs.
Expression parser runtime data crates/ruff_python_parser/src/parser/expression.rs, crates/ruff_python_parser/src/parser/helpers.rs, crates/ruff_python_parser/src/parser/recovery.rs
Expression parser paths initialize runtime_* fields for args, containers, strings, comparisons, and comprehensions, and constant literals are recognized in parser helpers and recovery.
Statements, module, and pattern runtime data crates/ruff_python_parser/src/parser/mod.rs, crates/ruff_python_parser/src/parser/statement.rs, crates/ruff_python_parser/src/parser/pattern.rs
Module, statement, and pattern parsing paths initialize the corresponding runtime_* fields on bodies, decorators, targets, match patterns, parameters, and type parameters.
Comparable and helper logic treat Expr::Constant and ConstantValue as literal-like values for comparison, hashing, truthiness, singleton detection, operator precedence, and relocation.
Traversal and visitor updates crates/ruff_python_ast/src/node.rs, crates/ruff_python_ast/src/visitor.rs, crates/ruff_python_ast/src/visitor/source_order.rs, crates/ruff_python_ast/src/visitor/transformer.rs, crates/ruff_python_ast/src/generated.rs
Traversal code visits Expr::Constant and broadens struct patterns to ignore the added runtime_* fields in source-order, walker, and transformer paths.
Estimated code review effort
🎯 4 (Complex) | ⏱️ ~60 minutes
Poem
I hopped through Expr::Constant with a twitching nose,
And tucked runtime_* carrots where the AST grows.
I nibbled truthiness, then bounded through the trees,
While visitors and parsers rustled in the breeze.
🐇✨
✨ Finishing Touches📝 Generate docstrings
Create stacked PR
Commit on current branch
🧪 Generate unit tests (beta)
Create PR with unit tests
Commit unit tests in branch runtime-field
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.
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
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
Test Plan
Summary by CodeRabbit
New Features
Bug Fixes
None, and ellipsis-style constants in expression analysis and precedence detection.