Add explicit Python collection conversion adapters by 1ndahous3 · Pull Request #9372 · RustPython/RustPython
Repository navigation
Add explicit Python collection conversion adapters - #9372
Open
1ndahous3 wants to merge 3 commits into RustPython:main from 1ndahous3:py_collection_adapters
Open
Add explicit Python collection conversion adapters #9372 1ndahous3 wants to merge 3 commits into RustPython:main from 1ndahous3:py_collection_adapters
Conversation
1ndahous3
commented
Oct 25, 2026
·
edited by coderabbitai
Bot
Loading
Copy link Copy Markdown
Contributor
This proposal comes from my personal project, br3k , which uses an embedded RustPython VM:
- Definitions: custom
PyListOf<T>adapter . - Usage: returning process modules as a Python list .
- Stub generation: mapping
PyListOf<T>tolist[T].
The call_between_rust_and_python example also had its own list conversion wrapper.
Summary
- Add
PyListOf<T>,PySetOf<T>andPyDictOf<K, V>for constructing Python collections from Rust iterators. Explicit list conversion includesu8without changingVec<u8>conversion tobytes. - Use Python hashing and equality for sets and dictionaries, propagating construction errors and stopping at the failing item.
- Preserve collection identity when cloning or returning an adapter, with GC traversal of the owned reference.
- Keep element access untyped: type parameters describe construction, while Python can subsequently mutate the collections.
- Replace manual collection conversion in CSV dialect listing, signal sets, and
sys._current_frames()/sys._current_exceptions()while preserving snapshots and object identity. - Show built-in list conversion alongside a custom domain conversion in the embedding example.
Example
let labels = PyListOf::new(["ready", "done"], vm);
let flags = PySetOf::try_new([1, 2, 1], vm)?;
let counts = PyDictOf::try_new([("ready", 2), ("done", 1)], vm)?;
AI assistance
Written with Codex (GPT-6), reviewed by a human before submission.
Summary by CodeRabbit
- New Features
- Added typed helpers for creating Python lists, dictionaries, and sets from Rust values. Dictionary keys and set items follow Python equality and duplicate-handling behavior.
- Expanded the Rust-Python interoperability example with ordered measurements and list-based values.
Add an explicit Python list conversion adapter
64e8454
Assisted-by: Codex:GPT-6
Add dict and set conversion adapters
703a6b6
Assisted-by: Codex:GPT-6
Use collection adapters in CSV, signals and sys
10d7ff6
Assisted-by: Codex:GPT-6
chatgpt-codex-connector
Bot
commented
Oct 25, 2026
·
edited
Loading
Copy link Copy Markdown
Codex Review SummaryThis comment shows the latest Codex review activity on this pull request.
Your team has set up Codex to review pull requests in this repo . Reviews are triggered when you
Codex reacts with 👀 while any review is running, comments if it has suggestions, and reacts with 👍 once all reviews finish with no findings. |
coderabbitai
Bot
commented
Oct 25, 2026
·
edited
Loading
Copy link Copy Markdown
Contributor
|
No actionable comments were generated in the recent review. Recent review info
10d7f
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 |
Bot
reviewed Oct 25, 2026
View reviewed changes
chatgpt-codex-connector
Bot
left a comment
Copy link Copy Markdown
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more .
💡 Codex Review
Here are some automated review suggestions for this pull request.
Reviewed commit: 10d7ff6d53
Codex has been enabled to automatically review pull requests in this repo. Reviews are triggered when you
- Open a pull request for review
- Mark a draft as ready
- Comment "@codex review".
If Codex has suggestions, it will comment; otherwise it will react with 👍.
When you sign up for Codex through ChatGPT , Codex can also answer questions or update the PR, like "@codex address that feedback".
youknowone commented Oct 26, 2026
Copy link Copy Markdown
Member
|
this is interesting idea, but let me look in details. |