Separate Debug from PyPayload by youknowone · Pull Request #6320 · RustPython/RustPython
Walkthrough
This PR refactors the VM object system's trait bounds, replacing PyObjectPayload with PyPayload across public APIs and adding std::fmt::Debug constraints to ensure debug-printability. The PyPayload trait itself is narrowed by removing Debug from supertraits, with Debug requirements instead added to specific methods via where clauses.
Changes
| Cohort / File(s) | Summary |
|---|---|
Foundational trait updates crates/vm/src/object/payload.rs |
Removed std::fmt::Debug from PyPayload supertrait; added where Self: std::fmt::Debug to five public methods (into_pyobject, _into_ref, into_exact_ref, into_ref, into_ref_with_type). Updated PyObjectPayload impl to require Debug on generic parameter. |
Object system refactoring crates/vm/src/object/core.rs, crates/vm/src/object/ext.rs |
Broadly replaced PyObjectPayload with PyPayload across downcasting APIs, trait impls (Borrow, AsRef, Hash, PartialEq, Eq, Debug), and weak reference handling. Added std::fmt::Debug bounds to debug-related functions and trait implementations. Updated PyRef, Py<T>, PyWeakRef<T>, PyExact<T>, PyRefExact<T>, PyLease<'a, T>, and PyAtomicRef<T> generic constraints. |
Trait bound additions crates/vm/src/builtins/dict.rs, crates/vm/src/types/slot.rs, crates/vm/src/vm/context.rs |
Added std::fmt::Debug constraint to DictView::ReverseIter associated type, DefaultConstructor trait supertraits, and Context::new_pyref<T, P> generic parameter. |
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~20 minutes
Areas requiring extra attention:
- payload.rs: The removal of Debug from trait supertraits and shift to method-level where clauses should be verified to ensure all implementors can satisfy the constraints without breaking downstream code.
- core.rs & ext.rs: The large-scale replacement of
PyObjectPayloadwithPyPayloadacross many impl blocks should be spot-checked for completeness and correctness, particularly in downcasting and weak reference paths. - Trait impact: Verify that the Debug constraints on
PyPayloadmethods do not conflict with existing trait object usage patterns or generic specializations.
Possibly related PRs
- Integrate PyTupleTyped into PyTuple #5959: Overlapping refactors to payload/traverse/type-bounds in the same files (payload.rs, object/core.rs, vm/context.rs), modifying related trait bounds and APIs.
- Downcastable #5986: Related changes to PyObject downcasting APIs in object/core.rs affecting downcast/payload methods and trait bounds.
Suggested reviewers
- arihant2math
- coolreader18
Poem
🐰 Debug bounds hop through every trait,
PyPayload now leads our fate,
Constraints tighten, types align—
Where clauses make the code just fine,
A refactor clean, no bugs in sight!
Pre-merge checks and finishing touches
❌ Failed checks (1 warning)
| Check name | Status | Explanation | Resolution |
|---|---|---|---|
| Docstring Coverage | 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 (2 passed)
| Check name | Status | Explanation |
|---|---|---|
| Description Check | ✅ Passed | Check skipped - CodeRabbit’s high-level summary is enabled. |
| Title check | ✅ Passed | The title 'Separate Debug from PyPayload' accurately captures the main objective of this PR, which systematically decouples the Debug trait requirement from the PyPayload trait across the codebase. |
✨ Finishing touches
- 📝 Generate docstrings
🧪 Generate unit tests (beta)
- Create PR with unit tests
- Post copyable unit tests in a 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.
Comment @coderabbitai help to get the list of available commands and usage tips.