#6427·pyo3

`IntoPyObject` doesn't intern dictionary keys

Author: vasiliy-poverennov-ddCreated Sep 17, 2026Updated Sep 17, 2026

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

bash

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