PyO3 / PyO3/pyo3

`IntoPyObject` doesn't intern dictionary keys

Open
#6,427 2 comments 0 reactions 0 assignees View on GitHub

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

https://github.com/PyO3/pyo3/blob/4df5ac6296fa9c9a375d874082a8ad90e43f9b2d/pyo3-macros-backend/src/frompyobject.rs#L400

https://github.com/PyO3/pyo3/blob/4df5ac6296fa9c9a375d874082a8ad90e43f9b2d/pyo3-macros-backend/src/intopyobject.rs#L283

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

Open the contributing guide

First steps

  1. Read the whole issue, then the project's contributing guide.
  2. Comment on the issue to say you are picking it up — it saves two people doing the same work.
  3. Fork the repository and make your change on a branch.
  4. 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

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.