impl more ast by youknowone · Pull Request #6419 · RustPython/RustPython
Walkthrough
This PR refactors AST pattern handling in the Rust VM stdlib, replacing placeholder implementations with concrete vector-based structs. Three PatternMatchClass related structures now wrap vectors instead of ranges. Functions for splitting and merging pattern arguments are updated to handle actual data conversions for Singleton values and pattern components.
Changes
| Cohort / File(s) | Summary |
|---|---|
Pattern AST Refactoring crates/vm/src/stdlib/ast/pattern.rs |
Refactored PatternMatchClassPatterns, PatternMatchClassKeywordAttributes, and PatternMatchClassKeywordPatterns from placeholder range-based structs to vector-based newtype wrappers. Implemented trait methods (ast_to_object, ast_from_object) for ruff::Singleton to convert between Python objects (None, True, False) and Rust enum variants. Updated split_pattern_match_class and merge_pattern_match_class to construct and deconstruct public vector-based components with proper keyword pattern handling. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
- Struct representation changes: Verify that the newtype wrapper conversions correctly delegate to inner vectors and handle edge cases.
- Singleton implementation: Ensure
ast_to_objectandast_from_objectproperly map between Python objects and enum variants, and that error handling is complete. - split/merge function logic: Carefully review the
merge_pattern_match_classconstruction ofPatternKeyworditems with proper range and node_index defaults to ensure correct round-tripping of AST data.
Poem
🐰 From ranges sparse to vectors full of might,
We pack our patterns tight, a refactor's delight.
Singletons sing true—None, False, and True—
Now serialized and round-tripped, the old TODOs are through! ✨
Pre-merge checks and finishing touches
❌ Failed checks (1 warning, 1 inconclusive)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | Docstring coverage is 9.09% which is insufficient. The required threshold is 80.00%. | You can run @coderabbitai generate docstrings to improve docstring coverage. |
|
| Title check | ❓ Inconclusive | The title 'impl more ast' is vague and generic, using non-descriptive terms that don't convey meaningful information about the specific changes made. | Consider using a more descriptive title that reflects the specific implementation, such as 'Implement proper serialization for Singleton and vector-based PatternMatchClass structures' or similar. |
✅ Passed checks (1 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
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 @coderabbitai help to get the list of available commands and usage tips.