Repository navigation
Re-order variants to prioritize narrower types - #31504
Conversation
As of pybind/pybind11#5879, pybind11 will convert Python `int` to C `float`/`double`. For `std::variant`, pybind11 will attempt to convert arguments in the order of the type. So if `double` occurs earlier in the variant, then `int`/`long` will never be produced. By putting `int`/`long` before `double`, pybind11 will attempt that conversion first and we'll continue to produce our deprecation warning correctly. Fixes matplotlib#31495
|
Can we add this to the coding guidelines? (it's 100% the type of thing I'd forget when reviewing new C++ code) |
|
Confirmed that this works for me. Once we have this version of pybind11 in CI it will be very start failing hard so I'm not super worried about documenting it. |
|
or, if it goes in anyone's docs it should be pybind11's. |
|
Also, as a note, these variants should go away after branching 3.11 as they are deprecations to be removed in 3.12. So we hopefully would not have to worry about it for too long. |
|
Ah, am I being too excited about back-porting this to 3.10 as well then? |
|
No, it should go to 3.10 as well; the deprecations started in 3.10. |
…504-on-v3.10.x Backport PR #31504 on branch v3.10.x (Re-order variants to prioritize narrower types)
PR summary
As of pybind/pybind11#5879, pybind11 will convert Python
intto Cfloat/double. Forstd::variant, pybind11 will attempt to convert arguments in the order of the type.So if
doubleoccurs earlier in the variant, thenint/longwill never be produced. By puttingint/longbeforedouble, pybind11 will attempt that conversion first and we'll continue to produce our deprecation warning correctly.Fixes #31495
AI Disclosure
None
PR checklist