GeezerVisonThe World Wide Web, restored to 800 pixels of glory. | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
| Home|About|Gaming cabinet|Archives|How it works|Starter sites | ||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||||
GeezerVison is showing github.com — Update dataclasses, inspect from CPython 3.13 by youknowone · Pull Request #5377 · RustPython/RustPython Conversation
|
WalkthroughExtended AST pattern conversions: added full bidirectional mapping for Changes
Estimated code review effort🎯 4 (Complex) | ⏱️ ~45 minutes
Poem
Pre-merge checks and finishing touches❌ Failed checks (2 warnings)
✅ Passed checks (1 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 |
Sorry, something went wrong.
There was an error while loading. Please reload this page.
d4d8bda to
b6dfa84
Compare
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 0
crates/vm/src/stdlib/ast/pattern.rs (1)
210-227: Correct object-to-singleton conversion with minor formatting nit.The identity checks and error handling are appropriate. The conversion logic correctly distinguishes between the three singleton values.
Consider using display format
{}instead of debug format{:?}in the error message for cleaner output:} else { Err(vm.new_value_error(format!( - "Expected None, True, or False, got {:?}", + "Expected None, True, or False, got {}", object.class().name() ))) }
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Lib/dataclasses.py is excluded by !Lib/**Lib/dis.py is excluded by !Lib/**Lib/inspect.py is excluded by !Lib/**Lib/test/__init__.py is excluded by !Lib/**Lib/test/test__opcode.py is excluded by !Lib/**Lib/test/test_abc.py is excluded by !Lib/**Lib/test/test_compile.py is excluded by !Lib/**Lib/test/test_copy.py is excluded by !Lib/**Lib/test/test_dataclasses/__init__.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_1.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_1_str.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_2.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_2_str.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_textanno.py is excluded by !Lib/**Lib/test/test_enum.py is excluded by !Lib/**Lib/test/test_fstring.py is excluded by !Lib/**Lib/test/test_inspect/__init__.py is excluded by !Lib/**Lib/test/test_inspect/inspect_fodder.py is excluded by !Lib/**Lib/test/test_inspect/inspect_fodder2.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stock_annotations.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stringized_annotations.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stringized_annotations_2.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stringized_annotations_pep695.py is excluded by !Lib/**Lib/test/test_inspect/test_inspect.py is excluded by !Lib/**Lib/test/test_unittest/testmock/testhelpers.py is excluded by !Lib/**Lib/test/test_warnings/__init__.py is excluded by !Lib/**crates/vm/src/stdlib/ast/pattern.rs (1 hunks)📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/vm/src/stdlib/ast/pattern.rscrates/vm/src/stdlib/ast/pattern.rs (1)
202-208: LGTM! Clean singleton-to-object conversion.The exhaustive pattern match correctly maps each
Singletonvariant to its corresponding VM object representation.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
crates/vm/src/stdlib/ast/pattern.rs (1)
543-558: Avoid cloningkwd_attrs(optional)
split_pattern_match_classcurrently clonesattrbecause it later consumesarguments.keywords. You can split attrs/patterns in a single consuming loop to avoid clones.
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
Lib/dataclasses.py is excluded by !Lib/**Lib/dis.py is excluded by !Lib/**Lib/inspect.py is excluded by !Lib/**Lib/test/test__opcode.py is excluded by !Lib/**Lib/test/test_abc.py is excluded by !Lib/**Lib/test/test_compile.py is excluded by !Lib/**Lib/test/test_copy.py is excluded by !Lib/**Lib/test/test_dataclasses/__init__.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_1.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_1_str.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_2.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_module_2_str.py is excluded by !Lib/**Lib/test/test_dataclasses/dataclass_textanno.py is excluded by !Lib/**Lib/test/test_enum.py is excluded by !Lib/**Lib/test/test_fstring.py is excluded by !Lib/**Lib/test/test_inspect/__init__.py is excluded by !Lib/**Lib/test/test_inspect/inspect_fodder.py is excluded by !Lib/**Lib/test/test_inspect/inspect_fodder2.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stock_annotations.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stringized_annotations.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stringized_annotations_2.py is excluded by !Lib/**Lib/test/test_inspect/inspect_stringized_annotations_pep695.py is excluded by !Lib/**Lib/test/test_inspect/test_inspect.py is excluded by !Lib/**Lib/test/test_unittest/testmock/testhelpers.py is excluded by !Lib/**Lib/test/test_warnings/__init__.py is excluded by !Lib/**crates/vm/src/stdlib/ast/pattern.rs (3 hunks)📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by runningcargo fmtto format Rust code
Always run clippy to lint Rust code (cargo clippy) before completing tasks and fix any warnings or lints introduced by changes
Follow Rust best practices for error handling and memory management
Use the macro system (pyclass,pymodule,pyfunction, etc.) when implementing Python functionality in Rust
Files:
crates/vm/src/stdlib/ast/pattern.rscrates/vm/src/stdlib/itertools.rs (1)
None(1152-1152)crates/vm/src/stdlib/ast/other.rs (1)
object(39-39)crates/vm/src/builtins/genericalias.rs (1)
arguments(66-66)crates/vm/src/frame.rs (1)
kwd_attrs(1122-1122)crates/vm/src/stdlib/functools.rs (1)
keywords(72-74)
crates/vm/src/stdlib/ast/pattern.rs (1)
390-435: Wrapper types look fine; delegation is cleanThe tuple-struct wrappers +
Nodedelegation keep thePatternMatchClassconversion code simpler and should round-trip as long asVec<T>: Nodeandruff::Identifier: Nodebehave as expected.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
| /// Merges the pattern match class attributes and patterns, opposite of [`split_pattern_match_class`]. | ||
| fn merge_pattern_match_class( | ||
| _patterns: PatternMatchClassPatterns, | ||
| _kwd_attrs: PatternMatchClassKeywordAttributes, | ||
| _kwd_patterns: PatternMatchClassKeywordPatterns, | ||
| patterns: PatternMatchClassPatterns, | ||
| kwd_attrs: PatternMatchClassKeywordAttributes, | ||
| kwd_patterns: PatternMatchClassKeywordPatterns, | ||
| ) -> (Vec<ruff::Pattern>, Vec<ruff::PatternKeyword>) { | ||
| todo!() | ||
| let keywords = kwd_attrs | ||
| .0 | ||
| .into_iter() | ||
| .zip(kwd_patterns.0) | ||
| .map(|(attr, pattern)| ruff::PatternKeyword { | ||
| range: Default::default(), | ||
| node_index: Default::default(), | ||
| attr, | ||
| pattern, | ||
| }) | ||
| .collect(); | ||
| (patterns.0, keywords) | ||
| } |
There was a problem hiding this comment.
The reason will be displayed to describe this comment to others. Learn more.
Don’t silently truncate mismatched kwd_attrs / kwd_patterns lengths
zip will drop extras if lengths differ. Since ast_from_object accepts user-constructed AST objects, this should error instead of losing data.
Low-impact fix: validate in ruff::PatternMatchClass::ast_from_object (where vm is available) before calling merge_pattern_match_class:
let kwd_attrs = Node::ast_from_object(
vm, source_file, get_node_field(vm, &object, "kwd_attrs", "MatchClass")?
)?;
let kwd_patterns = Node::ast_from_object(
vm, source_file, get_node_field(vm, &object, "kwd_patterns", "MatchClass")?
)?;
+
+if kwd_attrs.0.len() != kwd_patterns.0.len() {
+ return Err(vm.new_value_error(format!(
+ "MatchClass kwd_attrs and kwd_patterns must have the same length ({} != {})",
+ kwd_attrs.0.len(),
+ kwd_patterns.0.len(),
+ )));
+}
let (patterns, keywords) = merge_pattern_match_class(patterns, kwd_attrs, kwd_patterns);Committable suggestion skipped: line range outside the PR's diff.
In crates/vm/src/stdlib/ast/pattern.rs around lines 560 to 578, the current
merge_pattern_match_class uses zip and silently drops extra entries when
kwd_attrs and kwd_patterns lengths differ; instead, validate that
kwd_attrs.0.len() == kwd_patterns.0.len() before merging (preferably in
ruff::PatternMatchClass::ast_from_object where the VM is available) and
return/raise a TypeError (or appropriate VM error) if they differ with a clear
message indicating mismatched keyword attributes and patterns lengths; only
after validation, construct PatternKeyword entries and return the merged
vectors.
Sorry, something went wrong.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
There was an error while loading. Please reload this page.
Successfully merging this pull request may close these issues.
There was an error while loading. Please reload this page.