Skip to content

Re-order variants to prioritize narrower types#31504

Merged
story645 merged 1 commit intomatplotlib:mainfrom
QuLogic:variant-priority
Apr 16, 2026
Merged

Re-order variants to prioritize narrower types#31504
story645 merged 1 commit intomatplotlib:mainfrom
QuLogic:variant-priority

Conversation

@QuLogic
Copy link
Copy Markdown
Member

@QuLogic QuLogic commented Apr 16, 2026

PR summary

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 #31495

AI Disclosure

None

PR checklist

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
@story645
Copy link
Copy Markdown
Member

Can we add this to the coding guidelines? (it's 100% the type of thing I'd forget when reviewing new C++ code)
https://matplotlib.org/devdocs/devel/coding_guide.html#c-c-extensions

@QuLogic QuLogic added this to the v3.11.0 milestone Apr 16, 2026
@tacaswell tacaswell added the Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. label Apr 16, 2026
@tacaswell tacaswell modified the milestones: v3.11.0, v3.10.9 Apr 16, 2026
@tacaswell
Copy link
Copy Markdown
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.

@tacaswell
Copy link
Copy Markdown
Member

or, if it goes in anyone's docs it should be pybind11's.

@QuLogic
Copy link
Copy Markdown
Member Author

QuLogic commented Apr 16, 2026

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.

@tacaswell
Copy link
Copy Markdown
Member

Ah, am I being too excited about back-porting this to 3.10 as well then?

@QuLogic
Copy link
Copy Markdown
Member Author

QuLogic commented Apr 16, 2026

No, it should go to 3.10 as well; the deprecations started in 3.10.

@story645 story645 merged commit d6b33a2 into matplotlib:main Apr 16, 2026
59 of 60 checks passed
meeseeksmachine pushed a commit to meeseeksmachine/matplotlib that referenced this pull request Apr 16, 2026
@QuLogic QuLogic deleted the variant-priority branch April 16, 2026 20:32
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)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

backend: agg Release critical For bugs that make the library unusable (segfaults, incorrect plots, etc) and major regressions. topic: text/fonts

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Unavoidable warnings with pybind11 main branch

3 participants