-
Notifications
You must be signed in to change notification settings - Fork 1.4k
prefer nb_bool slot in try_to_bool instead of __bool__ #6328
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Conversation
|
Caution Review failedThe pull request is closed. WalkthroughPrioritizes a precomputed numeric boolean slot ( Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~25 minutes
Possibly related PRs
Poem
Pre-merge checks and finishing touches✅ Passed checks (5 passed)
📜 Recent review detailsConfiguration used: Path: .coderabbit.yml Review profile: CHILL Plan: Pro 📒 Files selected for processing (1)
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 |
Fixed: RustPython#6113 Signed-off-by: Yash Suthar <yashsuthar983@gmail.com>
50cff20 to
628f59e
Compare
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: 0
🧹 Nitpick comments (1)
crates/vm/src/builtins/bool.rs (1)
62-62: Consider renamingbool_objfor clarity.This variable holds the result of calling
__len__, which is an integer length, not a boolean. A name likelen_objorlen_resultwould be more semantically accurate.- let bool_obj = method.call((), vm)?; - let int_obj = bool_obj.downcast_ref::<PyInt>().ok_or_else(|| { + let len_obj = method.call((), vm)?; + let int_obj = len_obj.downcast_ref::<PyInt>().ok_or_else(|| { vm.new_type_error(format!( "'{}' object cannot be interpreted as an integer", - bool_obj.class().name() + len_obj.class().name() )) })?;
📜 Review details
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📒 Files selected for processing (1)
crates/vm/src/builtins/bool.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 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/builtins/bool.rs
🧬 Code graph analysis (1)
crates/vm/src/builtins/bool.rs (1)
crates/vm/src/builtins/range.rs (2)
__bool__(273-275)PyInt(389-390)
⏰ 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 tests under miri
- GitHub Check: Check the WASM package and demo
- GitHub Check: Run snippets and cpython tests on wasm-wasi
- 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
- GitHub Check: Run snippets and cpython tests (windows-latest)
- GitHub Check: Ensure compilation on various targets
- GitHub Check: Run rust tests (windows-latest)
- GitHub Check: Run rust tests (macos-latest)
- GitHub Check: Run rust tests (ubuntu-latest)
🔇 Additional comments (3)
crates/vm/src/builtins/bool.rs (3)
42-43: LGTM! Correct implementation of the nb_bool optimization path.This correctly prioritizes the precomputed boolean numeric slot over dynamic method resolution, aligning with the PR objective.
45-58: LGTM! Correct__bool__fallback with proper type validation.The error propagation, type checking, and value extraction are all handled correctly.
42-81: Well-structured implementation that correctly prioritizes nb_bool.The control flow properly implements the expected precedence (nb_bool → __bool__ → __len__ → default true), with appropriate error handling at each stage. This aligns with Python's truth value testing protocol and satisfies the PR objective.
youknowone
left a comment
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.
Thank you!
In principle, if the Python method __bool__ is defined, there must also be an nb_bool, so it seems there’s still some incorrect implementation left somewhere.
Fixed: #6113
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.