PyTypeFlags::{SEQUENCE,MAPPING} by youknowone · Pull Request #6109 · RustPython/RustPython
Walkthrough
Adds SEQUENCE and MAPPING type flags, applies them to builtin classes, and updates type creation to inherit/compute these flags (including via abc_tpflags). Also adds memoryview.class_getitem to support subscription-based generic aliasing. No runtime behavior changes beyond flag metadata and new classmethod.
Changes
| Cohort / File(s) | Summary |
|---|---|
Type flags definitionvm/src/types/slot.rs |
Adds PyTypeFlags::SEQUENCE and PyTypeFlags::MAPPING bitflags. |
Builtin type flag updatesvm/src/builtins/dict.rs, vm/src/builtins/list.rs, vm/src/builtins/tuple.rs, vm/src/builtins/range.rs, vm/src/builtins/memory.rs |
Updates #[pyclass] flags: dict gains MAPPING; list/tuple/range/memoryview gain SEQUENCE. |
Type creation flag propagationvm/src/builtins/type.rs |
On type creation, inherits SEQUENCE/MAPPING from base types and reads __abc_tpflags__ to set flags; integrates helpers into new_heap_inner and new_static. |
MemoryView generic aliasingvm/src/builtins/memory.rs |
Adds __class_getitem__(cls, args, vm) -> PyGenericAlias delegating to PyGenericAlias::from_args. |
Sequence Diagram(s)
sequenceDiagram
autonumber
actor Dev as Developer
participant VM as VM Type Creation
participant Base as Base Type
participant Helpers as Helpers
note over VM,Helpers: New type initialization
Dev->>VM: create type (heap/static)
VM->>Base: read existing flags
VM->>Helpers: inherit_patma_flags(SEQUENCE, MAPPING)
Helpers-->>VM: apply missing flags from base
VM->>Helpers: check_abc_tpflags(mro)
Helpers-->>VM: parse int bits, set flags (non-overriding)
VM-->>Dev: new type with updated PyTypeFlags
sequenceDiagram
autonumber
actor User as User Code
participant Type as memoryview (type)
participant VM as VM
participant GA as PyGenericAlias
User->>Type: memoryview[...]
Type->>Type: __class_getitem__(cls, args, vm)
Type->>GA: PyGenericAlias::from_args(cls, args, vm)
GA-->>Type: generic alias
Type-->>User: return alias
Estimated code review effort
🎯 3 (Moderate) | ⏱️ ~30 minutes
Possibly related PRs
- feat(vm/slot): implement
Py_TPFLAGS_MANAGED_DICTfor class objects #5949 — Also modifies PyTypeFlags and type initialization logic; overlaps with flag handling paths. - Deprecate ::new_ref #6046 — Touches builtin types in vm/src/builtins/*; related to updates of pyclass metadata.
- __class_getitem__ #5888 — Adds
__class_getitem__for memoryview; direct overlap with the new classmethod.
Poem
A rabbit taps flags with gentle delight,
SEQUENCE hops in, MAPPING holds tight.
Types learn from bases, like carrots from rows,
abc_tpflags whispers which way the wind blows.
memoryview[T] twinkles—alias in sight—
Code burrows deeper, and all feels right. 🥕
Tip
🔌 Remote MCP (Model Context Protocol) integration is now available!
Pro plan users can now connect to remote MCP servers from the Integrations page. Connect with popular remote MCPs such as Notion and Linear to add more context to your reviews and chats.
✨ Finishing Touches
- 📝 Generate Docstrings
🧪 Generate unit tests
- 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.
🪧 Tips
Chat
There are 3 ways to chat with CodeRabbit:
- Review comments: Directly reply to a review comment made by CodeRabbit. Example:
I pushed a fix in commit <commit_id>, please review it.Open a follow-up GitHub issue for this discussion.
- Files and specific lines of code (under the "Files changed" tab): Tag
@coderabbitaiin a new review comment at the desired location with your query. - PR comments: Tag
@coderabbitaiin a new PR comment to ask questions about the PR branch. For the best results, please provide a very specific query, as very limited context is provided in this mode. Examples:@coderabbitai gather interesting stats about this repository and render them as a table. Additionally, render a pie chart showing the language distribution in the codebase.@coderabbitai read the files in the src/scheduler package and generate a class diagram using mermaid and a README in the markdown format.
Support
Need help? Create a ticket on our support page for assistance with any issues or questions.
CodeRabbit Commands (Invoked using PR/Issue comments)
Type @coderabbitai help to get the list of available commands.
Other keywords and placeholders
- Add
@coderabbitai ignoreanywhere in the PR description to prevent this PR from being reviewed. - Add
@coderabbitai summaryto generate the high-level summary at a specific location in the PR description. - Add
@coderabbitaianywhere in the PR title to generate the title automatically.
Status, Documentation and Community
- Visit our Status Page to check the current availability of CodeRabbit.
- Visit our Documentation for detailed information on how to use CodeRabbit.
- Join our Discord Community to get help, request features, and share feedback.
- Follow us on X/Twitter for updates and announcements.