| FazBrowse GitHub Viewer | Trending | | Home |
| Tools: [Download Repo ZIP] [Original HTTPS Page] |
Sorry, something went wrong.
WalkthroughUpdates PyPayload trait to introduce a validate_downcastable_from extension point for custom downcast validation. Modifies PyUtf8Str to use this hook for UTF-8 validation without duplicate typeid checks. Updates PyNativeMethod to leverage the pyclass ctx parameter mechanism for type context. Changes
Estimated code review effort🎯 3 (Moderate) | ⏱️ ~20 minutes
Possibly related PRs
Suggested reviewers
Poem
Pre-merge checks and finishing touches❌ Failed checks (1 warning)
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. ❤️ ShareComment @coderabbitai help to get the list of available commands and usage tips. |
Sorry, something went wrong.
There was a problem hiding this comment.
Actionable comments posted: 0
🧹 Nitpick comments (2)crates/vm/src/object/payload.rs (1)📜 Review detailscrates/vm/src/builtins/str.rs (1)25-34: Clarify safety docs and contract for validate_downcastable_from
downcastable_from now performs the typeid check itself and then calls validate_downcastable_from. The safety comment (“should only be called if payload_type_id matches the type of obj”) no longer reflects the actual behavior, and override implementations (like PyUtf8Str) rely on the fact that validate_downcastable_from is only invoked after the typeid equality has been verified.
To make this extension point safer for future implementors, I suggest:
- Update the doc comment on downcastable_from to describe what guarantees it provides (e.g., that it first checks obj.typeid() == Self::payload_type_id()).
- Add a brief doc comment on validate_downcastable_from stating that, when called via downcastable_from, obj is guaranteed to satisfy the payload_type_id check, and that callers should not invoke it directly without that precondition.
This documents the intended use and justifies unsafe downcasts inside overrides like PyUtf8Str::validate_downcastable_from.
1935-1939: Unsafe cast in PyUtf8Str::validate_downcastable_from is sound but deserves a slightly stronger comment
The implementation:
- Overrides payload_type_id() to return TypeId::of::<PyStr>().
- Relies on PyPayload::downcastable_from to check obj.typeid() == TypeId::of::<PyStr>() before calling validate_downcastable_from.
- Then performs unsafe { obj.downcast_unchecked_ref::<PyStr>() } and checks is_utf8().
Given this call pattern, the unsafe cast is valid: when validate_downcastable_from runs, obj’s payload is guaranteed to be a PyStr, and PyUtf8Str is repr(transparent) over PyStr.
To make the invariant clearer for future changes, consider expanding the comment to mention that:
- validate_downcastable_from is only meant to be called via PyPayload::downcastable_from, and
- the preceding typeid check, together with the overridden payload_type_id(), is what justifies using downcast_unchecked_ref::<PyStr>() here.
Functionally the change looks correct and nicely reuses the new hook to avoid duplicating the type-id logic.
Configuration used: Path: .coderabbit.yml
Review profile: CHILL
Plan: Pro
📥 CommitsReviewing files that changed from the base of the PR and between 98fff96 and e4d0a58.
📒 Files selected for processing (3)📄 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/derive-impl/src/util.rs (1)⏰ 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). (2)
- base (416-418)
crates/vm/src/builtins/builtin_func.rs (1)151-155: ctx = "builtin_method_type" wiring for PyNativeMethod looks consistent
The added ctx = "builtin_method_type" on PyNativeMethod aligns with init() using context.types.builtin_method_type and removes the need for a separate PyPayload impl to provide class(ctx). This keeps the type wiring in one place and should preserve behavior for comparisons and calls that rely on downcast_ref::<PyNativeMethod>(), assuming the pyclass machinery provides the payload impl as expected.
Sorry, something went wrong.
| Back | FazBrowse Home | New Git URL |
Summary by CodeRabbit
✏️ Tip: You can customize this high-level summary in your review settings.