pyo3 icon indicating copy to clipboard operation
pyo3 copied to clipboard

use singleton in simple enum `IntoPyObject`

Open Icxolu opened this issue 1 month ago • 1 comments

This attempts solving #3059 by changing the generated IntoPyObject implementation for simple enums. This lazily stores the instances in a static array and creates them on first access.

This solves the issue for the cases where IntoPyObject is used, so for example the class attribute and function return types can now be compared by identity. This does not solve the issue that Py|Bound::new behave differently here. This is similar to #3747 as well. The solution for that is probably to remove the impl<T> From<T> for PyClassInitializer<T> blanket and instead emit customized code via #[pyclass]. That could be done as a follow up.

Icxolu avatar Nov 30 '25 19:11 Icxolu

The solution for that is probably to remove the impl<T> From<T> for PyClassInitializer<T> blanket and instead emit customized code via #[pyclass]. That could be done as a follow up.

👍 I think there's a bunch of improvement we could do the initializer API, also with how subclassing works etc.

davidhewitt avatar Dec 07 '25 10:12 davidhewitt