GeezerVison is showing github.com — Update `test_{descr,super}.py` from 3.13.9 by ShaharNaveh · Pull Request #6314 · RustPython/RustPython
Conversation
ShaharNaveh
commented
Nov 29, 2025
•
edited by coderabbitai
Bot
Loading
Uh oh!
There was an error while loading. Please reload this page.
Summary by CodeRabbit
- Bug Fixes
- Improved handling of
super() when given mismatched type/instance combinations to avoid spurious checks and preserve existing subclass/instance routing.
- Enhanced error messages for incompatible
super(type, obj) calls, providing clearer descriptions of whether obj is a type or instance and naming the offending types for easier troubleshooting.
✏️ Tip: You can customize this high-level summary in your review settings.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
coderabbitai
Bot
commented
Nov 29, 2025
•
edited
Loading
Uh oh!
There was an error while loading. Please reload this page.
Walkthrough
Reworked super_check in crates/vm/src/builtins/super.rs to add an initial typ-based path for PyType detection, preserve existing isinstance/class routing, and produce a more descriptive error when obj is not an instance or subtype of the provided type.
Changes
| Cohort / File(s) |
Summary |
Enhanced super() type checking crates/vm/src/builtins/super.rs |
Add an initial typ extraction path to detect PyType without immediate subclass check; keep existing isinstance and __class__ routing; build a clearer error message reporting whether obj is a type or an instance and include type names; no other control-flow changes. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
- Inspect the new typ-extraction logic and its interaction with the existing subclass checks.
- Verify correctness and safety of downcasts used to obtain type names for error messages.
- Confirm that existing
isinstance and __class__-based paths behave identically after the change.
Suggested reviewers
Poem
🐰 I hopped through code where types entwine,
peered at classes, instance and sign.
Now errors chant what once was blind,
“Type or instance?” — the answer aligned.
A joyful twitch, a clearer design.
Pre-merge checks and finishing touches
❌ Failed checks (2 warnings)
| Check name |
Status |
Explanation |
Resolution |
| Title check |
⚠️ Warning |
The PR title mentions updating test files from 3.13.9, but the actual changes are in super.rs with logic modifications to super_check and error handling. |
Revise the title to reflect the actual changes: e.g., 'Improve super_check error reporting and type validation logic' or 'Refactor super_check downcast handling and error messages'. |
| Docstring Coverage |
⚠️ Warning |
Docstring coverage is 0.00% which is insufficient. The required threshold is 80.00%. |
You can run @coderabbitai generate docstrings to improve docstring coverage. |
✅ Passed checks (1 passed)
| Check name |
Status |
Explanation |
| Description Check |
✅ Passed |
Check skipped - CodeRabbit’s high-level summary is enabled. |
✨ Finishing touches
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a comment
📜 Recent review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between c2ea003 and 7c86523.
📒 Files selected for processing (1)
crates/vm/src/builtins/super.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by running cargo fmt to 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/builtins/super.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Run tests under miri
- GitHub Check: Check Rust code with clippy
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
🔇 Additional comments (1)
crates/vm/src/builtins/super.rs (1)
242-270: I'm unable to verify the review comment because the repository failed to clone. Without access to the actual file crates/vm/src/builtins/super.rs, I cannot confirm:
- Whether the code snippet provided matches the current state of the file
- Whether unsafe downcasts were actually eliminated as claimed
- Whether the error message construction properly reuses the stored
typ value
- Whether previous review concerns were genuinely addressed
Additionally, the review comment requests verification using cargo fmt and cargo clippy, which cannot be executed in the sandbox environment (Rust toolchain is unavailable).
Please provide the repository or file contents directly so I can complete the verification. Alternatively, if you have access to run the verification commands in your environment, please share those results.
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.
❤️ Share
Comment @coderabbitai help to get the list of available commands and usage tips.
|
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Actionable comments posted: 1
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 Commits
Reviewing files that changed from the base of the PR and between 6782fa2 and c2ea003.
⛔ Files ignored due to path filters (2)
Lib/test/test_descr.py is excluded by !Lib/**
Lib/test/test_super.py is excluded by !Lib/**
📒 Files selected for processing (1)
crates/vm/src/builtins/super.rs (1 hunks)
🧰 Additional context used
📓 Path-based instructions (1)
**/*.rs
📄 CodeRabbit inference engine (.github/copilot-instructions.md)
**/*.rs: Follow the default rustfmt code style by running cargo fmt to 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/builtins/super.rs
⏰ Context from checks skipped due to timeout of 90000ms. You can increase the timeout in your CodeRabbit configuration to a maximum of 15 minutes (900000ms). (11)
- GitHub Check: Run rust tests (ubuntu-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- GitHub Check: Run tests under miri
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run snippets and cpython tests (macos-latest)
- GitHub Check: Run snippets and cpython tests (ubuntu-latest)
- GitHub Check: Check Rust code with clippy
🔇 Additional comments (1)
crates/vm/src/builtins/super.rs (1)
269-274: LGTM! Enhanced error message provides better debugging information.
The error message now clearly distinguishes between type and instance arguments and includes their names, making it much easier to diagnose super() misuse.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Comment on lines
+242
to
+267
|
|
let is_type = match obj.clone().downcast::<PyType>() {
|
|
|
Ok(cls) if cls.fast_issubclass(&ty) => return Ok(cls),
|
|
|
Ok(_) => true,
|
|
|
Err(_) => false,
|
|
|
};
|
|
|
|
|
|
if obj.fast_isinstance(&ty) {
|
|
|
return Ok(obj.class().to_owned());
|
|
|
}
|
|
|
|
|
|
let class_attr = obj.get_attr("__class__", vm)?;
|
|
|
if let Ok(cls) = class_attr.downcast::<PyType>()
|
|
|
&& !cls.is(&ty)
|
|
|
&& cls.fast_issubclass(&ty)
|
|
|
{
|
|
|
return Ok(cls);
|
|
|
}
|
|
|
Err(vm.new_type_error("super(type, obj): obj must be an instance or subtype of type"))
|
|
|
|
|
|
let (type_or_instance, obj_str) = if is_type {
|
|
|
// SAFETY: This is will always be successful as we already checked at the begining of
|
|
|
// the function.
|
|
|
let typ = unsafe { obj.downcast::<PyType>().unwrap_unchecked() };
|
|
|
("type", typ.name().to_owned())
|
|
|
} else {
|
|
|
("instance of", obj.class().name().to_owned())
|
|
|
};
|
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
⚠️ Potential issue | 🟡 Minor
Fix typo and avoid unsafe downcast by storing the type.
Line 261 has a typo: "This is will always be successful" should be "This will always be successful".
More importantly, the unsafe downcast at line 263 can be avoided. The current code discards the downcasted PyType in the Ok(_) branch at line 244, then later performs an unsafe downcast to retrieve it. Instead, store the downcasted type when is_type is true and reuse it, eliminating the need for unsafe code.
Apply this diff to fix the typo and avoid unsafe:
- let is_type = match obj.clone().downcast::<PyType>() {
+ let obj_type = match obj.clone().downcast::<PyType>() {
Ok(cls) if cls.fast_issubclass(&ty) => return Ok(cls),
- Ok(_) => true,
- Err(_) => false,
+ Ok(cls) => Some(cls),
+ Err(_) => None,
};
+ let is_type = obj_type.is_some();
if obj.fast_isinstance(&ty) {
return Ok(obj.class().to_owned());
}
let class_attr = obj.get_attr("__class__", vm)?;
if let Ok(cls) = class_attr.downcast::<PyType>()
&& !cls.is(&ty)
&& cls.fast_issubclass(&ty)
{
return Ok(cls);
}
- let (type_or_instance, obj_str) = if is_type {
- // SAFETY: This is will always be successful as we already checked at the begining of
- // the function.
- let typ = unsafe { obj.downcast::<PyType>().unwrap_unchecked() };
- ("type", typ.name().to_owned())
+ let (type_or_instance, obj_str) = if let Some(typ) = obj_type {
+ ("type", typ.name().to_owned())
} else {
("instance of", obj.class().name().to_owned())
};
🤖 Prompt for AI Agents
crates/vm/src/builtins/super.rs around lines 242-267: the code currently throws
away the successful downcasted PyType in the match and later does an unsafe
downcast and has a typo in the comment; change the match to capture and store
the downcasted PyType (e.g. Option<PyTypeRef> or similar) instead of a boolean
flag, use that stored PyType when building type_or_instance (avoiding unsafe
downcast), update the comment to "This will always be successful", and remove
the unsafe unwrap_unchecked usage so the stored safe reference is reused.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
ShaharNaveh reacted with thumbs up emoji
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Sorry, something went wrong.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
Assignees
No one assigned
Milestone
No milestone
Development
Successfully merging this pull request may close these issues.
Uh oh!
There was an error while loading. Please reload this page.
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.
|