◐ Shell
clean mode source ↗

sequence, mapping slots and fix separate __delitem__ slots by youknowone · Pull Request #6621 · RustPython/RustPython

📝 Walkthrough

Walkthrough

This PR removes PyO3 #[pymethod] exposure from many special methods (contains, len, set, delete, repr), refactors descriptor slot variants to separate set/del semantics, updates slot resolution logic, and adds AsMapping support for ctypes array/pointer types.

Changes

Cohort / File(s) Summary
Remove #[pymethod] from __contains__
crates/vm/src/builtins/bytearray.rs, crates/vm/src/builtins/bytes.rs, crates/vm/src/builtins/dict.rs, crates/vm/src/builtins/list.rs, crates/vm/src/builtins/mappingproxy.rs, crates/vm/src/builtins/range.rs, crates/vm/src/builtins/str.rs, crates/vm/src/builtins/tuple.rs, crates/vm/src/builtins/weakproxy.rs, crates/stdlib/src/array.rs, crates/vm/src/stdlib/collections.rs
Removed #[pymethod] annotations from __contains__ implementations; Rust functions remain but are no longer exposed as Python methods.
Remove #[pymethod] from __len__
crates/stdlib/src/array.rs, crates/stdlib/src/contextvars.rs, crates/stdlib/src/mmap.rs, crates/vm/src/builtins/range.rs
Removed #[pymethod] annotations from __len__ implementations; implementations unchanged but no longer Python-exposed.
Remove #[pymethod] from descriptor/setter/deleter methods
crates/vm/src/builtins/dict.rs, crates/vm/src/builtins/getset.rs, crates/vm/src/builtins/property.rs, crates/vm/src/stdlib/ctypes/base.rs
Deleted Python-exposed __set__/__delete__ (and __sizeof__/other decorator removals) from various descriptor and ctypes field types; internal helper paths remain.
Remove Python-level __repr__ wrapper
crates/vm/src/exception_group.rs
Removed Python-exposed __repr__ for PyBaseExceptionGroup; representation now relies on the slot implementation.
Descriptor slot variants and wrapper logic
crates/vm/src/builtins/descriptor.rs
Renamed SeqAssItemSeqSetItem, MapAssSubscriptMapSetSubscript; added SeqDelItem and MapDelSubscript; wrapper calls now pass Some(value) for set and None for delete and bind arguments accordingly.
Slot resolution and slot_defs rework
crates/vm/src/types/slot.rs, crates/vm/src/types/slot_defs.rs
Slot resolution for sequence/mapping ass_subscript now distinguishes set vs del: checks for own __setitem__/__delitem__, looks up SeqSetItem/SeqDelItem or MapSetSubscript/MapDelSubscript in MRO, updates accessor mappings and SLOT_DEFS ordering.
Add mapping protocol support for ctypes
crates/vm/src/stdlib/ctypes/array.rs, crates/vm/src/stdlib/ctypes/pointer.rs
Added AsMapping impls and PyMappingMethods for PyCArray and PyCPointer; updated #[pyclass(..., with(...))] to include AsMapping, delegating mapping ops to existing get/set/del item logic.

Estimated code review effort

🎯 4 (Complex) | ⏱️ ~45 minutes

Possibly related PRs

Suggested reviewers

  • ShaharNaveh
  • arihant2math

Poem

🐇 I hopped through slots with nimble feet,

Set and del now dance discrete.
Methods hidden, protocols grown,
Mapping added, seeds were sown.
A rabbit cheers for code well-known. 🎉

Pre-merge checks and finishing touches

❌ Failed checks (1 warning)
Check name Status Explanation Resolution
Docstring Coverage ⚠️ Warning Docstring coverage is 41.18% 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 summarizes the main changes: refactoring sequence and mapping slot definitions, separating delitem into distinct slots (SeqDelItem, MapDelSubscript), and fixing related slot handling logic.
✨ Finishing touches
  • 📝 Generate docstrings

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.