Skip to content

Conversation

@youknowone
Copy link
Member

@youknowone youknowone commented Dec 17, 2025

Summary by CodeRabbit

  • Refactor
    • Consolidated object ownership and reference handling across many internals for more consistent memory semantics.
    • More consistent CSV parsing behavior and clearer type-related error messages for delimiters, quoting, escape and line terminators.
    • Unified exception referencing and rendering paths for clearer tracebacks and exception context handling.
    • Adjusted container view and sequence access semantics to stabilize mapping/proxy and iteration behavior.

✏️ Tip: You can customize this high-level summary in your review settings.

@coderabbitai
Copy link
Contributor

coderabbitai bot commented Dec 17, 2025

Walkthrough

This PR shifts many internal APIs to use owned/wrapper types (Py<T>, PyObject) instead of borrowed refs (PyRef<T>, PyObjectRef, PyBaseExceptionRef, etc.), updating signatures and call sites across stdlib, VM builtins, ctypes, exception handling, and related modules.

Changes

Cohort / File(s) Summary
CSV module
crates/stdlib/src/csv.rs
Parsing helpers changed from &PyObjectRef&PyObject and use .to_owned(); error messages refined for quote/escape/lineterminator/quoting parsing.
Exception handling / SSL / WASM
crates/stdlib/src/openssl.rs, crates/stdlib/src/ssl/compat.rs, crates/wasm/src/convert.rs, crates/vm/src/exceptions.rs, crates/vm/src/coroutine.rs, crates/vm/src/vm/mod.rs, crates/vm/src/import.rs
Many functions changed from PyBaseExceptionRefPy<PyBaseException> (signatures updated for write_exception, contextualize/set context, is_gen_exit, remove_importlib_frames, py_err_to_js_err, etc.). Small import/export ordering edits.
scproxy / dict view / JIT
crates/stdlib/src/scproxy.rs, crates/vm/src/builtins/dict.rs, crates/vm/src/builtins/function/jit.rs
Dict types moved from PyDictRefPy<PyDict>: closure signatures, DictView::dict() trait, macro impls, JIT arg lookup updated; mapping proxy construction uses .to_owned().
Sequence & collection element access
crates/vm/src/builtins/list.rs, crates/vm/src/stdlib/collections.rs, crates/vm/src/sequence.rs
MutObjectSequenceOp::do_get return type changed from Option<&PyObjectRef>Option<&PyObject>; callers use `.map(
Tuple/tuple-like & codecs
crates/vm/src/builtins/genericalias.rs, crates/vm/src/codecs.rs
Helpers (tuple_index, unpack detection) now accept &PyObject; subs_tvars and tuple-returning APIs moved from &PyTupleRef&Py<PyTuple>; PyCodec::as_tuple() signature updated.
Type / payload / ConstName
crates/vm/src/builtins/type.rs, crates/vm/src/object/payload.rs, crates/vm/src/vm/context.rs
new_simple_heap and payload error helpers now take &Py<PyType> (instead of PyTypeRef); ConstName::new accepts &Py<PyType> and uses to_owned().
Property / builtin function
crates/vm/src/builtins/property.rs, crates/vm/src/builtins/builtin_func.rs
Internal closures and helpers adjusted from &PyObjectRef&PyObject; PyNativeFunction::get_self() return type changed to Option<&PyObject> and is non-const.
ctypes (multiple files)
crates/vm/src/stdlib/ctypes.rs, crates/vm/src/stdlib/ctypes/base.rs, crates/vm/src/stdlib/ctypes/field.rs, crates/vm/src/stdlib/ctypes/structure.rs, crates/vm/src/stdlib/ctypes/union.rs
APIs updated to accept PyObject in many helpers (e.g., new_simple_type uses Either<&PyObject, &PyTypeRef>; get_field_size/get_field_align and value_to_bytes use &PyObject); ownership handling standardized via .to_owned().
Exception group / derive logic
crates/vm/src/exception_group.rs
Multiple helpers converted to PyObject / Py<PyBaseException> signatures; get_condition_matcher and derive_and_copy_attributes expanded for tuple/type/Callable handling and attribute propagation.
Formatting / scope / suggestions / warnings / frame
crates/vm/src/cformat.rs, crates/vm/src/stdlib/builtins.rs, crates/vm/src/stdlib/typevar.rs, crates/vm/src/suggestion.rs, crates/vm/src/warn.rs, crates/vm/src/frame.rs
Numerous helper params switched from PyObjectRefPyObject and some exception refs to Py<PyBaseException>; set_module_from_caller and related helpers updated; small comment prototype change in scope.
Misc small API adjustments
crates/vm/src/stdlib/ctypes/field.rs, crates/vm/src/stdlib/ctypes/structure.rs, crates/stdlib/src/ssl.rs, crates/wasm/src/js_module.rs
Local helpers updated to new owned/wrapper types; some .clone().to_owned() conversions and minor import edits.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~60 minutes

  • Pay particular attention to:
    • exception group derivation and attribute-copy semantics (crates/vm/src/exception_group.rs)
    • ctypes field size/align and type-discovery fallbacks (crates/vm/src/stdlib/ctypes/*)
    • propagation of DictView::dict() change across all impls/consumers (crates/vm/src/builtins/dict.rs)
    • places switching from borrowed refs to Py<...> for lifetime/ownership correctness in VM exception paths

Possibly related PRs

Suggested reviewers

  • ShaharNaveh
  • arihant2math

Poem

🐰
I nibbled refs and found them light,
Swapped clones for to_owned — what a sight!
Py snug in a burrow neat,
PyObject hops on nimble feet.
Cheers — the VM's now tidy and bright!

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 77.53% which is insufficient. The required threshold is 80.00%. You can run @coderabbitai generate docstrings to improve docstring coverage.
✅ Passed checks (2 passed)
Check name Status Explanation
Description Check ✅ Passed Check skipped - CodeRabbit’s high-level summary is enabled.
Title check ✅ Passed The title accurately describes the main objective of this PR: systematically replacing PyRef and PyObjectRef patterns with Py and PyObject types throughout the codebase.
✨ Finishing touches
  • 📝 Generate docstrings
🧪 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 da6b45c and 905c706.

📒 Files selected for processing (17)
  • crates/stdlib/src/openssl.rs (2 hunks)
  • crates/stdlib/src/scproxy.rs (2 hunks)
  • crates/stdlib/src/ssl/compat.rs (3 hunks)
  • crates/vm/src/builtins/dict.rs (5 hunks)
  • crates/vm/src/builtins/function/jit.rs (2 hunks)
  • crates/vm/src/builtins/genericalias.rs (2 hunks)
  • crates/vm/src/builtins/union.rs (1 hunks)
  • crates/vm/src/codecs.rs (1 hunks)
  • crates/vm/src/coroutine.rs (2 hunks)
  • crates/vm/src/exception_group.rs (3 hunks)
  • crates/vm/src/exceptions.rs (6 hunks)
  • crates/vm/src/import.rs (2 hunks)
  • crates/vm/src/scope.rs (1 hunks)
  • crates/vm/src/suggestion.rs (3 hunks)
  • crates/vm/src/vm/mod.rs (3 hunks)
  • crates/wasm/src/convert.rs (2 hunks)
  • crates/wasm/src/js_module.rs (1 hunks)
🚧 Files skipped from review as they are similar to previous changes (7)
  • crates/stdlib/src/openssl.rs
  • crates/vm/src/vm/mod.rs
  • crates/wasm/src/convert.rs
  • crates/vm/src/builtins/genericalias.rs
  • crates/vm/src/suggestion.rs
  • crates/stdlib/src/scproxy.rs
  • crates/vm/src/scope.rs
🧰 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/wasm/src/js_module.rs
  • crates/vm/src/codecs.rs
  • crates/vm/src/coroutine.rs
  • crates/vm/src/exception_group.rs
  • crates/vm/src/import.rs
  • crates/stdlib/src/ssl/compat.rs
  • crates/vm/src/builtins/function/jit.rs
  • crates/vm/src/builtins/dict.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/builtins/union.rs
🧠 Learnings (4)
📚 Learning: 2025-12-09T08:46:58.660Z
Learnt from: youknowone
Repo: RustPython/RustPython PR: 6358
File: crates/vm/src/exception_group.rs:173-185
Timestamp: 2025-12-09T08:46:58.660Z
Learning: In crates/vm/src/exception_group.rs, the derive() method intentionally always creates a BaseExceptionGroup instance rather than preserving the original exception class type. This is a deliberate design decision that differs from CPython's behavior.

Applied to files:

  • crates/wasm/src/js_module.rs
  • crates/vm/src/coroutine.rs
  • crates/vm/src/exception_group.rs
  • crates/vm/src/import.rs
  • crates/vm/src/exceptions.rs
📚 Learning: 2025-11-10T06:27:41.954Z
Learnt from: youknowone
Repo: RustPython/RustPython PR: 6243
File: vm/src/function/buffer.rs:123-129
Timestamp: 2025-11-10T06:27:41.954Z
Learning: In vm/src/function/buffer.rs, line 36 in the try_rw_bytes_like method intentionally uses TypeError (not BufferError) for the "buffer is not a read-write bytes-like object" error case, even though a similar error message in ArgMemoryBuffer::try_from_borrowed_object uses BufferError. The TypeError is the intended exception type for this specific code path.

Applied to files:

  • crates/wasm/src/js_module.rs
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to Lib/**/*.py : Minimize modifications to CPython standard library files in the `Lib/` directory; modifications should be minimal and only to work around RustPython limitations

Applied to files:

  • crates/vm/src/import.rs
  • crates/stdlib/src/ssl/compat.rs
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust

Applied to files:

  • crates/vm/src/import.rs
🧬 Code graph analysis (3)
crates/wasm/src/js_module.rs (1)
crates/vm/src/builtins/type.rs (1)
  • new_simple_heap (176-189)
crates/vm/src/exception_group.rs (4)
crates/vm/src/exceptions.rs (4)
  • obj (221-221)
  • obj (225-225)
  • obj (395-395)
  • obj (403-403)
crates/vm/src/stdlib/ctypes/function.rs (3)
  • typ (34-35)
  • t (86-86)
  • t (364-364)
crates/vm/src/stdlib/ctypes/array.rs (4)
  • typ (80-85)
  • typ (464-466)
  • t (82-82)
  • t (90-90)
crates/vm/src/frame.rs (1)
  • func (2121-2122)
crates/vm/src/builtins/function/jit.rs (1)
crates/vm/src/builtins/dict.rs (1)
  • dict (756-756)
⏰ 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: Ensure compilation on various targets
  • GitHub Check: Run rust tests (windows-latest)
  • GitHub Check: Run rust tests (macos-latest)
  • GitHub Check: Run snippets and cpython tests (windows-latest)
  • GitHub Check: Check the WASM package and demo
  • GitHub Check: Check Rust code with clippy
  • GitHub Check: Run snippets and cpython tests (ubuntu-latest)
  • GitHub Check: Run rust tests (ubuntu-latest)
  • GitHub Check: Run snippets and cpython tests (macos-latest)
  • GitHub Check: Run tests under miri
🔇 Additional comments (23)
crates/stdlib/src/ssl/compat.rs (3)

26-29: LGTM! Import updates align with the signature changes below.

The addition of PyBaseException and Py imports properly supports the type signature changes from &PyBaseExceptionRef to &Py<PyBaseException>.


987-989: LGTM! Correct simplification of reference type.

Changing from &PyBaseExceptionRef (i.e., &PyRef<PyBaseException>) to &Py<PyBaseException> removes unnecessary indirection since PyRef<T> derefs to Py<T>. The function body using fast_isinstance remains valid as it's available on Py<T>.


1537-1556: LGTM! Consistent with the pattern applied throughout this PR.

The signature change to &Py<PyBaseException> is correct. All method calls (fast_isinstance, as_object, get_attr, try_int, try_to_primitive) are properly available on Py<PyBaseException>.

crates/vm/src/import.rs (2)

3-10: LGTM! Import reorganization is clean and correct.

The imports are properly updated to include Py and PyBaseException from exceptions::types, supporting the signature change in remove_importlib_frames.


208-218: LGTM! Signature change is correct and body remains valid.

The change from &PyBaseExceptionRef to &Py<PyBaseException> properly simplifies the reference type. All method calls (fast_isinstance, __traceback__, set_traceback_typed) work correctly on Py<PyBaseException>.

crates/vm/src/exceptions.rs (6)

79-86: LGTM! Entry point for exception writing correctly updated.

The signature change to &Py<PyBaseException> is appropriate and cascades consistently to the internal helper methods.


88-129: LGTM! Recursive exception writing with proper type handling.

The parameter change is correct. The get_id() and recursive calls work properly with &Py<PyBaseException>. The &cause_or_context reference on line 121 correctly passes a reference to the inner Py<PyBaseException>.


132-170: LGTM! Inner exception writing logic remains valid.

All method accesses (.traceback.read(), .args(), .class(), .as_object()) are properly available on Py<PyBaseException>.


177-183: LGTM! SyntaxError formatting with updated types.

Both exc: &Py<PyBaseException> and exc_type: &Py<PyType> parameter types are correct. The &Py<PyType> change aligns with the broader pattern of this PR.


370-385: LGTM! Traceback entry writing correctly uses &Py<PyTraceback>.

The change from &PyTracebackRef to &Py<PyTraceback> is consistent with the PR pattern. Field accesses (.frame, .lineno) work correctly on the Py<PyTraceback> type.


1053-1064: LGTM! SerializeException struct and constructor updated consistently.

The struct field and new() parameter now use &'s Py<PyBaseException> instead of &'s PyBaseExceptionRef. This removes unnecessary indirection while maintaining the same functionality. The SerializeExceptionOwned variant (line 1067-1070) correctly retains PyBaseExceptionRef since it owns the exception rather than borrowing it.

crates/wasm/src/js_module.rs (1)

615-615: LGTM! Type signature change aligns with PR objective.

The type passing for vm.ctx.exceptions.exception_type is correct—it's a &'static Py<PyType> that satisfies the &Py<PyType> parameter of new_simple_heap. The Rust compiler enforces type correctness at compile time, and this change maintains type safety.

crates/vm/src/coroutine.rs (2)

2-2: LGTM! Imports correctly support the type system change.

The addition of Py and PyBaseException imports aligns with the shift to owned/wrapper types and supports the updated is_gen_exit signature.

Also applies to: 5-5


211-213: Type mismatch: function signature incompatible with current call site.

The signature change to &Py<PyBaseException> introduces a compilation error. At line 168, the error type e from PyResult is PyBaseExceptionRef (alias for PyRef<PyBaseException>), not Py<PyBaseException>. These are incompatible types. Either update PyResult to use Py<PyBaseException> as its error type, or revert the function signature to accept &PyBaseExceptionRef.

⛔ Skipped due to learnings
Learnt from: youknowone
Repo: RustPython/RustPython PR: 6243
File: vm/src/function/buffer.rs:123-129
Timestamp: 2025-11-10T06:27:41.954Z
Learning: In vm/src/function/buffer.rs, line 36 in the try_rw_bytes_like method intentionally uses TypeError (not BufferError) for the "buffer is not a read-write bytes-like object" error case, even though a similar error message in ArgMemoryBuffer::try_from_borrowed_object uses BufferError. The TypeError is the intended exception type for this specific code path.
crates/vm/src/exception_group.rs (3)

355-429: LGTM! Clean type refactoring.

The signature changes from &PyObjectRef/&PyRef<T> to &PyObject/&Py<T> are consistent with the PR's goal. The shift from clone() to to_owned() at lines 412 and 424 correctly expresses the intent of converting borrowed references to owned references. All downcast_ref usages remain appropriate for borrowed types.


431-469: LGTM! Signature change preserves all functionality.

The parameter type change from &PyRef<PyBaseException> to &Py<PyBaseException> aligns with the PR objective. All attribute access patterns (__traceback__(), __context__(), __cause__(), as_object()) work correctly with the new type, and the metadata propagation logic remains intact.


355-469: Run cargo clippy to verify no lints are introduced.

Per the coding guidelines, clippy must be run on all Rust changes before completion. While the code appears structurally sound with proper error handling and memory management, the clippy check must be executed to ensure no warnings are introduced by these helper functions.

crates/vm/src/builtins/function/jit.rs (2)

3-5: LGTM! Import addition aligns with signature refactor.

The addition of PyDict to the imports is necessary for the updated function signature on line 47. Keeping PyDictRef ensures compatibility with existing call sites.


47-47: Type coercion from &PyDictRef to &Py<PyDict> is correct. The signature change is valid because PyDictRef is a type alias for PyRef<PyDict>, and PyRef<T> implements Deref with Target = Py<T>. This allows &dict (where dict is PyDictRef) to automatically coerce to &Py<PyDict> at call sites (lines 98, 102, 121) via Rust's deref coercion mechanism. The pattern is sound and type-safe.

crates/vm/src/builtins/dict.rs (2)

756-756: LGTM! Trait signature updated consistently.

The return type change from &PyDictRef to &Py<PyDict> in the DictView trait aligns with the PR's objective to shift from borrowed refs to owned/wrapper types. The implementation in the dict_view! macro (line 788) correctly reflects this change.


1145-1145: No action needed. The type compatibility is correct.

The change from .clone() to .to_owned() is valid. When .to_owned() is called on &Py<PyDict>, it returns PyRef<PyDict> (alias PyDictRef) via the impl<T> ToOwned for Py<T> trait, which directly matches the existing impl From<PyDictRef> for PyMappingProxy. No type mismatch exists.

crates/vm/src/builtins/union.rs (1)

45-47: Review comment is based on incorrect assumptions and should be revised.

The method signature does not involve a const removal—no const qualifier appears on this method. The return type works through automatic Deref coercion: PyRef<T> implements Deref with target Py<T>, so &self.args (which is &PyRef<PyTuple>) automatically coerces to &Py<PyTuple>. This is a transparent implementation mechanism, not a breaking API change requiring downstream verification. The call sites in the codebase are already compatible.

Likely an incorrect or invalid review comment.

crates/vm/src/codecs.rs (1)

55-57: Method as_tuple() has no usages in the codebase; verification request cannot be completed.

The method returns &Py<PyTuple> and is technically correct due to Deref coercion from PyRef<PyTuple>, but it is dead code with zero call sites. The return type annotation returns a reference to an owned type, not an owned type itself, which conflicts with the stated goal of standardizing on owned Py<T> types. This method should either be removed if unused or its purpose clarified if it's part of a planned public API.

Likely an incorrect or invalid review 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.

❤️ Share

Comment @coderabbitai help to get the list of available commands and usage tips.

@youknowone youknowone marked this pull request as ready for review December 17, 2025 10:44
Copy link
Contributor

@coderabbitai coderabbitai bot left a 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

Caution

Some comments are outside the diff and can’t be posted inline due to platform limitations.

⚠️ Outside diff range comments (2)
crates/vm/src/stdlib/ctypes/base.rs (1)

51-77: Duplicate condition detected - second check is redundant.

Lines 54-61 check downcast_exact::<PyBytes> twice with identical logic. This appears to be a copy-paste error.

 fn set_primitive(_type_: &str, value: &PyObject, vm: &VirtualMachine) -> PyResult {
     match _type_ {
         "c" => {
             if value
                 .to_owned()
                 .downcast_exact::<PyBytes>(vm)
                 .is_ok_and(|v| v.len() == 1)
-                || value
-                    .to_owned()
-                    .downcast_exact::<PyBytes>(vm)
-                    .is_ok_and(|v| v.len() == 1)
                 || value
                     .to_owned()
                     .downcast_exact::<PyInt>(vm)
                     .map_or(Ok(false), |v| {
crates/stdlib/src/openssl.rs (1)

3354-3377: Type incompatibility between function signature and call sites requires fixing.

The function signature expects &Py<PyBaseException>, but call sites at lines 2500 and 2540 pass &PyBaseExceptionRef (returned from convert_ssl_error). These types are incompatible and will cause compilation errors. Either update the function signature to accept &PyBaseExceptionRef or convert the exception objects at call sites before passing them.

🧹 Nitpick comments (1)
crates/stdlib/src/scproxy.rs (1)

77-107: Type inconsistency between closure parameter and function return types.

The closure on line 77 accepts result: &Py<PyDict>, while both containing functions (lines 35, 70) declare return type PyResult<Option<PyDictRef>>. The result variable is created via vm.ctx.new_dict() on lines 40 and 75.

While the code compiles without errors, the types are inconsistent: the functions claim to return PyDictRef but use Py<PyDict> internally. For clarity and maintainability, align the function return types with the actual types being used, either adopting Py<PyDict> throughout or using PyDictRef consistently.

📜 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 9d2dd17 and da6b45c.

📒 Files selected for processing (36)
  • crates/stdlib/src/csv.rs (6 hunks)
  • crates/stdlib/src/openssl.rs (2 hunks)
  • crates/stdlib/src/scproxy.rs (2 hunks)
  • crates/stdlib/src/ssl.rs (3 hunks)
  • crates/stdlib/src/ssl/compat.rs (3 hunks)
  • crates/vm/src/builtins/builtin_func.rs (1 hunks)
  • crates/vm/src/builtins/dict.rs (5 hunks)
  • crates/vm/src/builtins/function/jit.rs (2 hunks)
  • crates/vm/src/builtins/genericalias.rs (2 hunks)
  • crates/vm/src/builtins/list.rs (1 hunks)
  • crates/vm/src/builtins/property.rs (3 hunks)
  • crates/vm/src/builtins/type.rs (1 hunks)
  • crates/vm/src/builtins/union.rs (1 hunks)
  • crates/vm/src/cformat.rs (5 hunks)
  • crates/vm/src/codecs.rs (1 hunks)
  • crates/vm/src/coroutine.rs (2 hunks)
  • crates/vm/src/exception_group.rs (3 hunks)
  • crates/vm/src/exceptions.rs (6 hunks)
  • crates/vm/src/frame.rs (1 hunks)
  • crates/vm/src/import.rs (2 hunks)
  • crates/vm/src/object/payload.rs (2 hunks)
  • crates/vm/src/scope.rs (1 hunks)
  • crates/vm/src/sequence.rs (2 hunks)
  • crates/vm/src/stdlib/builtins.rs (2 hunks)
  • crates/vm/src/stdlib/collections.rs (1 hunks)
  • crates/vm/src/stdlib/ctypes.rs (2 hunks)
  • crates/vm/src/stdlib/ctypes/base.rs (9 hunks)
  • crates/vm/src/stdlib/ctypes/field.rs (2 hunks)
  • crates/vm/src/stdlib/ctypes/structure.rs (3 hunks)
  • crates/vm/src/stdlib/ctypes/union.rs (2 hunks)
  • crates/vm/src/stdlib/typevar.rs (2 hunks)
  • crates/vm/src/suggestion.rs (3 hunks)
  • crates/vm/src/vm/context.rs (2 hunks)
  • crates/vm/src/vm/mod.rs (3 hunks)
  • crates/vm/src/warn.rs (2 hunks)
  • crates/wasm/src/convert.rs (2 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/codecs.rs
  • crates/vm/src/sequence.rs
  • crates/vm/src/builtins/list.rs
  • crates/vm/src/builtins/union.rs
  • crates/vm/src/vm/mod.rs
  • crates/vm/src/builtins/type.rs
  • crates/vm/src/frame.rs
  • crates/vm/src/coroutine.rs
  • crates/vm/src/stdlib/collections.rs
  • crates/vm/src/object/payload.rs
  • crates/vm/src/builtins/builtin_func.rs
  • crates/stdlib/src/ssl/compat.rs
  • crates/vm/src/scope.rs
  • crates/vm/src/stdlib/ctypes.rs
  • crates/vm/src/builtins/function/jit.rs
  • crates/vm/src/warn.rs
  • crates/vm/src/builtins/dict.rs
  • crates/vm/src/stdlib/typevar.rs
  • crates/vm/src/builtins/genericalias.rs
  • crates/vm/src/stdlib/builtins.rs
  • crates/vm/src/stdlib/ctypes/base.rs
  • crates/vm/src/suggestion.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/import.rs
  • crates/vm/src/stdlib/ctypes/field.rs
  • crates/stdlib/src/csv.rs
  • crates/wasm/src/convert.rs
  • crates/vm/src/builtins/property.rs
  • crates/vm/src/vm/context.rs
  • crates/stdlib/src/openssl.rs
  • crates/vm/src/exception_group.rs
  • crates/vm/src/cformat.rs
  • crates/stdlib/src/scproxy.rs
  • crates/vm/src/stdlib/ctypes/union.rs
  • crates/stdlib/src/ssl.rs
  • crates/vm/src/stdlib/ctypes/structure.rs
🧠 Learnings (5)
📓 Common learnings
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to Lib/**/*.py : Minimize modifications to CPython standard library files in the `Lib/` directory; modifications should be minimal and only to work around RustPython limitations
📚 Learning: 2025-12-09T08:46:58.660Z
Learnt from: youknowone
Repo: RustPython/RustPython PR: 6358
File: crates/vm/src/exception_group.rs:173-185
Timestamp: 2025-12-09T08:46:58.660Z
Learning: In crates/vm/src/exception_group.rs, the derive() method intentionally always creates a BaseExceptionGroup instance rather than preserving the original exception class type. This is a deliberate design decision that differs from CPython's behavior.

Applied to files:

  • crates/vm/src/vm/mod.rs
  • crates/vm/src/coroutine.rs
  • crates/vm/src/suggestion.rs
  • crates/vm/src/exceptions.rs
  • crates/vm/src/import.rs
  • crates/wasm/src/convert.rs
  • crates/stdlib/src/openssl.rs
  • crates/vm/src/exception_group.rs
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to Lib/**/*.py : Minimize modifications to CPython standard library files in the `Lib/` directory; modifications should be minimal and only to work around RustPython limitations

Applied to files:

  • crates/stdlib/src/ssl/compat.rs
  • crates/vm/src/import.rs
📚 Learning: 2025-11-29T12:17:28.606Z
Learnt from: CR
Repo: RustPython/RustPython PR: 0
File: .github/copilot-instructions.md:0-0
Timestamp: 2025-11-29T12:17:28.606Z
Learning: Applies to **/*.rs : Use the macro system (`pyclass`, `pymodule`, `pyfunction`, etc.) when implementing Python functionality in Rust

Applied to files:

  • crates/vm/src/stdlib/ctypes.rs
  • crates/vm/src/import.rs
  • crates/stdlib/src/csv.rs
📚 Learning: 2025-11-10T06:27:41.954Z
Learnt from: youknowone
Repo: RustPython/RustPython PR: 6243
File: vm/src/function/buffer.rs:123-129
Timestamp: 2025-11-10T06:27:41.954Z
Learning: In vm/src/function/buffer.rs, line 36 in the try_rw_bytes_like method intentionally uses TypeError (not BufferError) for the "buffer is not a read-write bytes-like object" error case, even though a similar error message in ArgMemoryBuffer::try_from_borrowed_object uses BufferError. The TypeError is the intended exception type for this specific code path.

Applied to files:

  • crates/vm/src/stdlib/ctypes/base.rs
  • crates/vm/src/exceptions.rs
  • crates/wasm/src/convert.rs
  • crates/vm/src/stdlib/ctypes/union.rs
  • crates/vm/src/stdlib/ctypes/structure.rs
🧬 Code graph analysis (13)
crates/vm/src/sequence.rs (3)
crates/vm/src/builtins/list.rs (2)
  • do_get (370-372)
  • index (265-278)
crates/vm/src/stdlib/collections.rs (2)
  • do_get (425-427)
  • index (165-187)
crates/vm/src/frame.rs (1)
  • elem (2541-2541)
crates/vm/src/builtins/list.rs (2)
crates/vm/src/sequence.rs (1)
  • do_get (15-15)
crates/vm/src/stdlib/collections.rs (2)
  • do_get (425-427)
  • index (165-187)
crates/vm/src/builtins/union.rs (3)
crates/vm/src/builtins/genericalias.rs (1)
  • args (102-102)
crates/vm/src/exceptions.rs (2)
  • args (568-570)
  • args (574-574)
crates/wasm/src/convert.rs (1)
  • args (227-231)
crates/vm/src/vm/mod.rs (1)
crates/vm/src/stdlib/sys.rs (1)
  • exception (341-343)
crates/vm/src/stdlib/collections.rs (2)
crates/vm/src/builtins/list.rs (2)
  • do_get (370-372)
  • index (265-278)
crates/vm/src/sequence.rs (1)
  • do_get (15-15)
crates/stdlib/src/ssl/compat.rs (2)
crates/vm/src/builtins/dict.rs (1)
  • err (82-84)
crates/vm/src/stdlib/io.rs (1)
  • vm (3519-3521)
crates/vm/src/stdlib/ctypes.rs (1)
crates/vm/src/frame.rs (2)
  • cls (1154-1155)
  • cls (1202-1203)
crates/vm/src/builtins/function/jit.rs (1)
crates/vm/src/builtins/dict.rs (1)
  • dict (756-756)
crates/vm/src/builtins/dict.rs (1)
crates/vm/src/object/core.rs (1)
  • dict (693-695)
crates/stdlib/src/csv.rs (5)
crates/vm/src/stdlib/collections.rs (1)
  • obj (448-449)
crates/vm/src/stdlib/ctypes/field.rs (4)
  • obj (106-106)
  • obj (115-115)
  • obj (200-200)
  • obj (217-217)
crates/stdlib/src/sqlite.rs (5)
  • obj (2090-2090)
  • obj (2091-2091)
  • obj (2943-2943)
  • obj (2948-2948)
  • obj (2951-2951)
crates/vm/src/stdlib/builtins.rs (4)
  • attr (230-230)
  • attr (408-408)
  • attr (429-429)
  • attr (831-831)
crates/vm/src/protocol/object.rs (1)
  • to_owned (381-381)
crates/vm/src/cformat.rs (2)
crates/vm/src/frame.rs (1)
  • element (596-596)
crates/vm/src/stdlib/io.rs (1)
  • vm (3519-3521)
crates/vm/src/stdlib/ctypes/union.rs (2)
crates/vm/src/stdlib/ctypes/structure.rs (2)
  • get_field_size (112-139)
  • field_type (277-278)
crates/vm/src/stdlib/ctypes.rs (1)
  • field_type (734-734)
crates/vm/src/stdlib/ctypes/structure.rs (2)
crates/vm/src/stdlib/ctypes/union.rs (1)
  • get_field_size (93-117)
crates/vm/src/stdlib/ctypes.rs (1)
  • field_type (734-734)
🔇 Additional comments (71)
crates/vm/src/builtins/type.rs (1)

176-189: LGTM! Clean ownership refactoring.

The signature and implementation changes correctly refactor from &PyTypeRef to &Py<PyType>, updating the conversion method from clone() to to_owned() to match the new type. This aligns with the broader PR objective of systematically removing &PyRef patterns in favor of Py<T> ownership semantics.

crates/vm/src/stdlib/typevar.rs (2)

47-68: LGTM!

The signature change from &PyObjectRef to &PyObject is a clean simplification. Callers using &obj_ref (where obj_ref: PyObjectRef) work seamlessly via auto-deref. The special-case handling for builtins and <...> module names correctly follows CPython behavior.


1008-1022: LGTM!

The signature changes from &PyObjectRef to &PyObject are consistent with the PR objective. The switch from .clone() to .to_owned() on line 1017 is the correct idiom for converting &PyObject to an owned PyObjectRef for assignment into the mutex-guarded field.

crates/vm/src/frame.rs (2)

1867-1872: LGTM! Parameter type change aligns with API migration.

The parameter type change from &PyObjectRef to &PyObject is consistent with the broader refactoring effort described in the PR objectives. Call sites correctly pass references that coerce to &PyObject through Rust's deref coercion.


1876-1876: LGTM! Using to_owned() is more idiomatic.

The change from clone() to to_owned() is more idiomatic when converting from a reference to an owned value, and correctly maintains the same semantics of creating an owned copy to pass to vm.get_method().

crates/vm/src/object/payload.rs (2)

107-117: LGTM! Consistent type refinement for error helper.

The parameter type change from &PyTypeRef to &Py<PyType> aligns with the PR's objective to remove PyRef patterns. The function logic remains unchanged, and the signature is now consistent with the second error helper function.


124-134: LGTM! Parallel type refinement maintains consistency.

The parameter type change from &PyTypeRef to &Py<PyType> mirrors the change in _into_ref_size_error, maintaining consistency between both error helper functions. The error message logic is preserved.

crates/vm/src/builtins/genericalias.rs (3)

297-299: LGTM! Signature refactored to use &PyObject.

The change from &PyObjectRef to &PyObject aligns with the PR's objective to remove useless reference patterns. All call sites (lines 263, 280, 329, 470) correctly pass compatible types from tuple iteration.


301-311: LGTM! Signature refactored to use &PyObject.

The parameter type change to &PyObject is consistent with the broader refactoring effort. The implementation correctly handles both the presence and absence of the __typing_is_unpacked_typevartuple__ attribute, returning the appropriate boolean value in each case.


313-357: LGTM! Signature refactored to use &Py<PyTuple>.

The parameter type change from &PyTupleRef to &Py<PyTuple> removes the type alias in favor of the direct type, aligning with the PR's refactoring goals. The implementation correctly uses as_slice() (line 329) and indexing operations (line 330) that are available on the new type. All call sites (lines 474, 478) pass compatible types.

crates/vm/src/scope.rs (1)

37-37: Clarify the refactoring scope for this file's PyDictRef usage.

Line 37's commented function signature was updated to &Py<PyDict>, but active code throughout this file (lines 1, 7, 19, 26) still uses PyDictRef. Given the PR goal to remove &PyRef patterns, either the active code should also be refactored or the comment update is premature. Please clarify the intended state.

crates/stdlib/src/scproxy.rs (1)

8-11: Complete the refactoring to use Py<PyDict> consistently.

Line 9 imports both PyDict and PyDictRef, but if this PR aims to replace PyRef patterns with owned types (Py<PyDict>), verify that PyDictRef is not used elsewhere in the file. If unused, remove it from the imports.

Additionally, run cargo fmt and cargo clippy to ensure the changes comply with Rust best practices.

crates/vm/src/stdlib/ctypes/union.rs (1)

10-10: LGTM! Consistent with the PR's type refactoring objective.

The signature change from &PyObjectRef to &PyObject aligns with the broader refactor. The implementation is identical to PyCStructType::get_field_size in structure.rs - consider extracting to a shared utility if this pattern continues.

Also applies to: 93-117

crates/vm/src/stdlib/ctypes/base.rs (1)

440-445: LGTM! Signature changes are consistent.

The value_to_bytes_endian signature update from &PyObjectRef to &PyObject is consistent with the refactor. The to_owned() call at line 603 is necessary since try_to_bool consumes ownership.

Also applies to: 603-607

crates/vm/src/stdlib/ctypes/field.rs (1)

4-4: LGTM! Consistent type refactoring.

The value_to_bytes signature change to &PyObject is appropriate. Call sites at lines 205 and 222 pass &value (where value: PyObjectRef), which correctly derefs to &PyObject.

Also applies to: 155-180

crates/vm/src/stdlib/ctypes/structure.rs (1)

10-10: LGTM! Signature updates align with the refactor.

Both get_field_size and get_field_align now accept &PyObject instead of &PyObjectRef. The call sites at lines 97, 273, and 274 correctly pass references that deref appropriately.

Also applies to: 112-139, 142-157

crates/vm/src/stdlib/ctypes.rs (1)

351-358: Signature Simplification is Correct and All Call Sites Are Compatible

The signature change from Either<&PyObjectRef, &PyTypeRef> to Either<&PyObject, &PyTypeRef> is verified as correct. The match implementation at lines 355-358 correctly unifies both variants to &PyObject:

  • Either::A(obj) directly returns the &PyObject
  • Either::B(typ) calls typ.as_object() to convert &PyTypeRef to &PyObject

All 13 call sites across ctypes.rs (line 438) and base.rs (lines 265, 291, 299, 309, 316, 329, 338, 346, 357, 365) pass Either::B(&cls) or Either::B(&type_ref), making them fully compatible with the updated signature. The as_object() method exists and is used throughout the codebase for type conversions.

crates/vm/src/builtins/union.rs (1)

45-47: LGTM!

The return type change from &PyTupleRef to &Py<PyTuple> is correct since PyRef<T> derefs to Py<T>. This aligns with the PR's goal of simplifying reference patterns while maintaining the same semantics.

crates/vm/src/codecs.rs (1)

55-57: LGTM!

The return type change from &PyTupleRef to &Py<PyTuple> is consistent with the PR's refactoring pattern. Since PyTupleRef derefs to Py<PyTuple>, returning a reference to the inner Py<PyTuple> is semantically equivalent.

crates/vm/src/sequence.rs (2)

15-15: LGTM!

The trait method signature change from Option<&PyObjectRef> to Option<&PyObject> is correct. The implementations in list.rs and collections.rs use .map(|r| r.as_ref()) to properly convert the reference.


79-79: LGTM!

Changing from elem.clone() to elem.to_owned() is correct since elem is now &PyObject. The to_owned() call creates an owned PyObject for use in rich_compare_bool.

crates/vm/src/vm/mod.rs (3)

26-26: LGTM!

The new import for PyBaseException is required to support the updated parameter types in the methods below.


730-741: LGTM!

The parameter type change from &PyBaseExceptionRef to &Py<PyBaseException> is consistent with the PR's refactoring pattern. The method body correctly uses exc.as_object() to access the underlying object.


818-832: LGTM!

The parameter type change from &PyBaseExceptionRef to &Py<PyBaseException> aligns with the PR's goal. All usages within the method (.is(), .__context__(), .set___context__()) work correctly with Py<PyBaseException>.

crates/vm/src/vm/context.rs (2)

65-69: LGTM!

The parameter type change from &PyTypeRef to &Py<PyType> and the corresponding typ.to_owned() call are correct. This aligns with the PR's refactoring pattern.


320-320: LGTM!

The call site correctly passes types.str_type (which is &'static Py<PyType>) directly to the updated ConstName::new signature.

crates/vm/src/builtins/list.rs (1)

370-372: LGTM!

The do_get implementation correctly aligns with the updated MutObjectSequenceOp trait signature. The .map(|r| r.as_ref()) properly converts &PyObjectRef to &PyObject, maintaining consistency with the trait definition in crates/vm/src/sequence.rs and the parallel PyDeque implementation.

crates/vm/src/stdlib/collections.rs (1)

425-427: LGTM!

The do_get implementation for PyDeque is consistent with the PyList implementation and correctly satisfies the updated MutObjectSequenceOp trait signature.

crates/wasm/src/convert.rs (1)

35-56: LGTM!

The signature change from &PyBaseExceptionRef to &Py<PyBaseException> aligns with the PR's goal. Since PyBaseExceptionRef is PyRef<PyBaseException> and PyRef<T> derefs to Py<T>, the call site at line 170 (py_err_to_js_err(vm, &err)) will work correctly through Rust's auto-deref coercion.

crates/vm/src/warn.rs (1)

41-52: LGTM!

The signature change from &PyObjectRef to &PyObject is consistent with the PR's refactoring goal. Call sites in get_filter (lines 131, 143) pass &PyObjectRef which correctly coerces to &PyObject through Rust's deref coercion.

crates/vm/src/stdlib/builtins.rs (1)

263-287: LGTM!

The parameter type change from &PyObjectRef to &PyObject for the internal validate_globals_dict helper is consistent with the PR's refactoring approach. The call site at line 291 correctly leverages auto-deref coercion.

crates/vm/src/builtins/dict.rs (3)

756-756: LGTM!

The return type change from &PyDictRef to &Py<PyDict> aligns with the PR's ownership semantics refactoring. Since PyDictRef is PyRef<PyDict> and PyRef<T> implements Deref<Target = Py<T>>, the macro implementation correctly returns &Py<PyDict> through deref coercion.


788-790: LGTM!

The macro implementation correctly satisfies the updated trait signature by returning &self.dict, which coerces from &PyRef<PyDict> to &Py<PyDict> through Rust's auto-deref.


1145-1145: LGTM!

The switch from .clone() to .to_owned() in the mapping getters is appropriate. Since dict() now returns &Py<PyDict> rather than &PyDictRef, calling .to_owned() correctly produces a PyRef<PyDict> via the ToOwned trait implementation, maintaining the same behavior.

Also applies to: 1209-1209, 1272-1272

crates/vm/src/builtins/builtin_func.rs (1)

54-58: LGTM!

The signature change from Option<&PyObjectRef> to Option<&PyObject> with as_deref() is correct. The removal of const fn is necessary since as_deref() is not a const function.

crates/vm/src/builtins/function/jit.rs (1)

47-67: LGTM!

The signature change from &PyDictRef to &Py<PyDict> aligns with the PR's goal. The call sites at lines 98, 102, and 121 pass &dict (where dict: PyDictRef), which works correctly via Deref coercion since PyDictRef derefs to Py<PyDict>.

crates/vm/src/cformat.rs (2)

209-224: LGTM!

The parameter type change to Option<&PyObject> is correct. The internal logic remains unchanged, and the function correctly handles the borrowed PyObject reference.


258-262: Correct adaptation of call sites.

The .map(|v| v.as_ref()) conversion from Option<&PyObjectRef> to Option<&PyObject> is the appropriate way to adapt the iterator elements to the updated function signature.

crates/stdlib/src/csv.rs (4)

134-151: LGTM!

The signature change to &PyObject and the use of obj.to_owned() for the match_class! macro are correct. The recursive call at line 136 with &attr works via Deref coercion.


152-172: LGTM!

The parameter type change is consistent with the broader refactoring pattern.


173-194: LGTM!

Signature correctly updated to accept &PyObject.


195-231: LGTM!

Both prase_lineterminator_from_obj and prase_quoting_from_obj are correctly updated to use &PyObject. Note: the "prase" typo in function names is pre-existing and unrelated to this PR.

crates/vm/src/exception_group.rs (5)

355-357: LGTM!

The parameter type change to &PyObject is correct and aligns with the refactoring goals.


359-370: LGTM!

Using &Py<PyBaseException> instead of &PyRef<PyBaseException> is consistent with the ownership model being established across the codebase.


378-416: LGTM!

The get_condition_matcher function correctly uses &PyObject for the condition parameter, and condition.to_owned() appropriately creates an owned reference when storing in the Callable variant.


418-429: LGTM!

The check method signature change to &PyObject is correct. The exc.to_owned() call at line 424 correctly converts the borrowed reference to an owned value for the function call.


431-469: LGTM!

The derive_and_copy_attributes function correctly uses &Py<PyBaseException> for the original exception reference. The logic for copying traceback, context, cause, and notes remains functionally equivalent.

crates/vm/src/coroutine.rs (2)

2-2: LGTM: Imports correctly updated for type migration.

The addition of Py and PyBaseException imports supports the function signature change in is_gen_exit, aligning with the broader migration from reference types to owned/wrapper types.

Also applies to: 5-5


211-213: LGTM: Function signature correctly updated.

The change from &PyBaseExceptionRef to &Py<PyBaseException> is consistent with the PR's objective to migrate from reference types to owned/wrapper types. The function body remains unchanged and fast_isinstance works identically with both parameter types.

crates/stdlib/src/ssl.rs (3)

1425-1432: LGTM: Parameter type correctly updated.

The change from PyObjectRef to &PyObject for the environ parameter is correct. The function body uses only methods that work with references (get_item, try_into_value), so no additional changes are needed internally.


2103-2113: LGTM: Reference parameter with internal cloning.

The change to accept &PyObject instead of PyObjectRef is correct. The function uses .to_owned() to create owned values when calling try_from_object, which is necessary since those functions expect PyObjectRef. This cloning pattern is acceptable for these helper functions as they're used during setup/initialization rather than hot paths.


2281-2290: LGTM: Consistent refactoring pattern.

The parameter type change from PyObjectRef to &PyObject follows the same pattern as parse_path_arg, using .to_owned() internally when owned values are required. This is consistent with the PR's objective to migrate toward using references instead of owned types at function boundaries.

crates/stdlib/src/openssl.rs (1)

59-60: LGTM - Transitional imports for type migration.

The addition of PyBaseException alongside PyBaseExceptionRef is appropriate for this incremental refactoring. Both types are needed during the migration period.

crates/stdlib/src/ssl/compat.rs (3)

26-29: LGTM - Import updates align with type migration.

The import changes correctly add PyBaseException and Py while maintaining PyBaseExceptionRef for transitional compatibility. This is the expected pattern during incremental refactoring.


987-989: LGTM - Signature change is consistent with PR objectives.

The change from &PyBaseExceptionRef to &Py<PyBaseException> is consistent with the PR's goal of removing reference type patterns. The function body uses fast_isinstance which is compatible with the new type.


1537-1556: LGTM - Helper function signature updated correctly.

The signature change follows the same pattern as is_blocking_io_error. The function body's use of fast_isinstance and attribute access methods are compatible with Py<PyBaseException>.

crates/vm/src/suggestion.rs (3)

5-8: LGTM - Import updates support type migration.

The import changes appropriately add Py and PyObject while replacing PyBaseExceptionRef with PyBaseException. This aligns with the broader refactoring effort.


50-76: LGTM - Exception type signature updated correctly.

The change from &PyBaseExceptionRef to &Py<PyBaseException> follows the standard refactoring pattern seen throughout the PR. The function body correctly uses the new type with methods like fast_isinstance and as_object().get_attr().


15-48: Verify PyObject vs PyObjectRef type change — CONFIRMED CORRECT.

The type change from &PyObjectRef to &PyObject is correct and all call sites have been properly updated. Since PyObjectRef is Rc<PyObject<dyn PyObjectPayload>>, &PyObjectRef can deref coerce to &PyObject, making the types compatible.

All four call sites (lines 55, 62, 67, 72) and the external call in crates/stdlib/src/suggestions.rs pass &PyObjectRef which is compatible with the function signature expecting &PyObject. The function body's use of downcast_ref works correctly with this parameter type.

crates/vm/src/import.rs (2)

4-9: LGTM - Import reorganization for type migration.

The import updates correctly add Py and PyBaseException while reorganizing the builtins imports. The changes support the type signature updates in this file.


208-219: LGTM - Function signature updated consistently.

The change from &PyBaseExceptionRef to &Py<PyBaseException> is consistent with the PR's refactoring pattern. The function body correctly uses fast_isinstance and traceback methods that are compatible with the new type.

crates/vm/src/exceptions.rs (7)

79-86: LGTM! Clean type refactoring for write_exception.

The parameter type change from &PyBaseExceptionRef to &Py<PyBaseException> removes redundant indirection (&PyRef<T>&Py<T>). The function logic is unchanged.

Note: This is a public API change. Ensure all call sites across the codebase have been updated to handle the new signature.


88-129: LGTM! Consistent type refactoring for write_exception_recursive.

The parameter type change aligns with the refactoring in write_exception. Function logic and recursive calls remain unchanged.


132-170: LGTM! Type refactoring for write_exception_inner.

The parameter type change is consistent with other exception handling functions. All field accesses and method calls work identically with the new &Py<PyBaseException> type.


177-279: LGTM! Type refactoring for write_syntaxerror.

The parameter type change maintains consistency with other exception writing methods. The complex syntax error formatting logic is unchanged and compatible with the new type.


370-385: LGTM! Type refactoring for write_traceback_entry.

Consistent with the exception type changes, this function now uses &Py<PyTraceback> instead of &PyTracebackRef. All field accesses remain valid.


1054-1064: LGTM! Type refactoring for SerializeException.

The struct field and constructor parameter types are updated consistently with the exception handling function changes. The straightforward constructor logic is preserved.

Note: This is a public API change for the serde feature. Ensure downstream serialization code is compatible.


55-77: The type coercion from &PyRef<T> to &Py<T> works correctly through Rust's Deref trait. PyRef derefs to a shared/immutable reference, and the RustPython implementation confirms this with impl<T> Deref for PyRef<T> { type Target = Py<T>; }, which allows automatic deref coercion of &PyRef<PyBaseException> to &Py<PyBaseException> when passed to write_exception. The code at lines 55-77 compiles successfully, with write_exception accepting &Py<PyBaseException> and receiving the dereferenced exception through standard Rust deref coercion. This pattern is intentional and part of a systematic refactoring.

crates/vm/src/builtins/property.rs (3)

312-333: Method parameter type updated correctly.

The format_property_error signature now accepts obj: &PyObject instead of &PyObjectRef, consistent with the PR's systematic refactoring. Call sites at lines 61, 111, and 119 pass &obj where obj: PyObjectRef, relying on automatic deref coercion.


359-363: Closure parameter type aligned with refactoring.

The get_getter_doc closure parameter type changed from &PyObjectRef to &PyObject. The call site at line 370 passes a value from args.fget.as_ref(), maintaining type compatibility through deref coercion.


269-274: Type change is sound and correctly implemented.

The closure parameter type change from &PyObjectRef to &PyObject aligns with the refactoring objectives. Rust's deref coercion automatically converts &PyObjectRef to &PyObject since PyObjectRef is Rc<PyObject<dyn PyObjectPayload>> and implements Deref<Target = PyObject>. The closure is invoked with values from .as_ref() on Option<PyObjectRef> at lines 278, 285, and 292, which deref coerces seamlessly. The storage types remain unchanged, and no logic modifications were introduced.

@youknowone youknowone merged commit a4c93df into RustPython:main Dec 17, 2025
13 checks passed
@youknowone youknowone deleted the pyref branch December 17, 2025 11:58
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant