Repository navigation
Unavoidable warnings with pybind11 main branch #31495
Copy link
Copy link
Closed
Labels
Milestone
Description
I am seeing warnings like
<ipython-input-4-1eb00ff78cf2>:1: MatplotlibDeprecationWarning: The x parameter as float was deprecated in Matplotlib 3.10 and will be removed in 3.12. Use int(x) instead.
plt.show()
<ipython-input-4-1eb00ff78cf2>:1: MatplotlibDeprecationWarning: The y parameter as float was deprecated in Matplotlib 3.10 and will be removed in 3.12. Use int(y) instead.
plt.show()
that come out on every draw ever for the simplest of plots (e.g. plt.gac(); plt.show()).
These are coming from
matplotlib/src/_backend_agg_wrapper.cpp
Lines 68 to 90 in 59eafb8
| if (auto value = std::get_if<double>(&vx)) { | |
| auto api = py::module_::import("matplotlib._api"); | |
| auto warn = api.attr("warn_deprecated"); | |
| warn("since"_a="3.10", "name"_a="x", "obj_type"_a="parameter as float", | |
| "alternative"_a="int(x)"); | |
| x = static_cast<int>(*value); | |
| } else if (auto value = std::get_if<int>(&vx)) { | |
| x = *value; | |
| } else { | |
| throw std::runtime_error("Should not happen"); | |
| } | |
| if (auto value = std::get_if<double>(&vy)) { | |
| auto api = py::module_::import("matplotlib._api"); | |
| auto warn = api.attr("warn_deprecated"); | |
| warn("since"_a="3.10", "name"_a="y", "obj_type"_a="parameter as float", | |
| "alternative"_a="int(y)"); | |
| y = static_cast<int>(*value); | |
| } else if (auto value = std::get_if<int>(&vy)) { | |
| y = *value; | |
| } else { | |
| throw std::runtime_error("Should not happen"); | |
| } |
these warnings triggering are due to a change in pybind11 (only see this with their development branch) and which I bisected to
e8e8d6ab22f39938607f31d457d4d359c130f078 is the first bad commit
commit e8e8d6ab22f39938607f31d457d4d359c130f078
Author: Michael Carlstrom <rmc@carlstrom.com>
Date: Mon Feb 16 23:00:01 2026 -0800
which came in via
matplotlib/src/_backend_agg_wrapper.cpp
Lines 68 to 90 in 59eafb8
| if (auto value = std::get_if<double>(&vx)) { | |
| auto api = py::module_::import("matplotlib._api"); | |
| auto warn = api.attr("warn_deprecated"); | |
| warn("since"_a="3.10", "name"_a="x", "obj_type"_a="parameter as float", | |
| "alternative"_a="int(x)"); | |
| x = static_cast<int>(*value); | |
| } else if (auto value = std::get_if<int>(&vx)) { | |
| x = *value; | |
| } else { | |
| throw std::runtime_error("Should not happen"); | |
| } | |
| if (auto value = std::get_if<double>(&vy)) { | |
| auto api = py::module_::import("matplotlib._api"); | |
| auto warn = api.attr("warn_deprecated"); | |
| warn("since"_a="3.10", "name"_a="y", "obj_type"_a="parameter as float", | |
| "alternative"_a="int(y)"); | |
| y = static_cast<int>(*value); | |
| } else if (auto value = std::get_if<int>(&vy)) { | |
| y = *value; | |
| } else { | |
| throw std::runtime_error("Should not happen"); | |
| } |
We either need to sort out how to adjust the pybind11 code or remove this warning.
Reactions are currently unavailable
Activity
Chirag3841 commentedon Apr 13, 2026
@tacaswell This seems to be caused by pybind11 resolving values as double, so std::get_if matches even for integers. We should either prioritize int over double in the variant handling or only warn when the float value is non-integral. Alternatively, fixing pybind11 to preserve integer types during casting would avoid this issue
QuLogic commentedon Apr 13, 2026
Should we report an issue upstream first? From the upstream PR, this affects
noconvertargs as well, so I don't know how we'd modify the type conversion priority.tacaswell commentedon Apr 14, 2026
I am not sure I have enough of a grasp on the problem to make a coherent upstream bug report nor the ability to write a minimal reproducer for them.
QuLogic commentedon Apr 16, 2026
I wrote up a minimal reproducer:
but as I was writing up the issue, I had an idea: if we swap the order of the
std::variant, then hopefully pybind11 will pick the non-double option first, and it seems to have worked in my testing.Re-order variants to prioritize narrower types
Re-order variants to prioritize narrower types (#31504)