Repository navigation
Changed constructor override order in Pybind11 3.1.0 #6152
neworderofjamie
started this conversation in
General
Replies: 1 comment
|
🤖 AI text below 🤖 Yes, this comes from #5879. The change is intentional (it follows the PEP 484 numeric tower), but the overload order now matters. pybind11 tries overloads in two passes. The first pass does not allow conversion. Since 3.1.0, a The fix is to register the pybind11::class_<NumericValue>(m, "NumericValue")
.def(pybind11::init<int64_t>())
.def(pybind11::init<double>())
.def_property_readonly("value", &NumericValue::get);A Python |
0 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Uh oh!
There was an error while loading. Please reload this page.
First of all, thanks for the amazing library! I have just isolated an issue that occurs when building our project with Pybind11 3.1.0 vs 3.0.4 and I was hoping for a suggestion for a workaround.
We have a class called
NumericValue, the relevant parts of which look like:This is wrapped for use in Python with:
With Pybind11 3.0.4, if you constructed a
NumericValuewith a Python integer, theint64_tconstructor was called but, with Pybind11 3.1.0, the double constructor gets called instead. At the suggestion of copilot, I have tried:int64_tconstructor:pybind11::int_valconstructor with a lambda function:.def(pybind11::init([](pybind11::int_ val){ return new Type::NumericValue(static_cast<int64_t>(val)); }), pybind11::arg("value").noconvert())Neither of which solve the problem! I am guessing this is related to #5879 but what's the correct solution here?
All reactions