`IntoPyObject` doesn't intern dictionary keys
Nobody has claimed this yet.
- Dominant language
- Rust
- Stars
- 16.2k
- Forks
- 1k
- Avg merge
- 2d 6h
- Merged PRs (30d)
- 66
Description
Bug Description
Not sure if this should be a bug or a feature request
it was surprising behavior for me and we had to switch from using derive to manually implementing IntoPyObject for some of the structs that get converted to python a lot to take advantage of key interning
FromPyObject derive interns the keys, IntoPyObject / IntoPyObjectRef don't - is this by design or an oversight? I think I should be able to put up a PR if you want this fixed
Steps to Reproduce
use IntoPyObject on a struct
Backtrace
Your operating system and version
MacOS 26
Your Python version (python --version)
Python 3.12.11
Your Rust version (rustc --version)
rustc 1.94.1
Your PyO3 version
0.29.2
How did you install python? Did you use a virtualenv?
not relevant
Additional Info
No response
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start by comparing pyo3-macros-backend/src/frompyobject.rs around line 400 with intopyobject.rs around line 283, then trace how IntoPyObject and IntoPyObjectRef derive dictionary keys. Confirm the behavior with a struct conversion example. Done means dictionary keys produced through the derives receive the same interning behavior as the corresponding FromPyObject path, with coverage for the reported case.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- python, rust
- Domain
- backend
- Issue type
- Bug
- Difficulty
- 3/5
- Estimated time
- 1-2 days
- Activity status
- Active
- Clarity
- Mostly clear
- Newbie friendliness
- 68/100