Re-order variants to prioritize narrower types#31504
Merged
story645 merged 1 commit intomatplotlib:mainfrom Apr 16, 2026
Merged
Re-order variants to prioritize narrower types#31504story645 merged 1 commit intomatplotlib:mainfrom
story645 merged 1 commit intomatplotlib:mainfrom
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
Member
|
Can we add this to the coding guidelines? (it's 100% the type of thing I'd forget when reviewing new C++ code) |
tacaswell
approved these changes
Apr 16, 2026
Member
|
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. |
Member
|
or, if it goes in anyone's docs it should be pybind11's. |
Member
Author
|
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. |
Member
|
Ah, am I being too excited about back-porting this to 3.10 as well then? |
Member
Author
|
No, it should go to 3.10 as well; the deprecations started in 3.10. |
story645
approved these changes
Apr 16, 2026
meeseeksmachine
pushed a commit
to meeseeksmachine/matplotlib
that referenced
this pull request
Apr 16, 2026
ksunden
added a commit
that referenced
this pull request
Apr 17, 2026
…504-on-v3.10.x Backport PR #31504 on branch v3.10.x (Re-order variants to prioritize narrower types)
This was referenced Apr 21, 2026
Closed
Merged
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
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