-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Implicit conversion from Null when inside a vector #1382
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I'm running into this same issue with a map. Did you ever figure out a workaround? |
No, unfortunately I haven't. If you come up with something please share. |
b_class.def("__init__" [](py::object o) {
if (o.is_none()) return B{};
else throw py::type_error("boom");
}); If this doesn't solve it, feel free to reopen the issue. |
Or |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can't make an implicit conversion from None (py::none or py::object) to my class work.
It is the same issue as #642 but I'd like to provide a non-obscure use case.
In the interface I'm writing I'd like to provide a constructor from a Python list. The elements of the list can be double, string and None (ideally). The constructor being exposed is this one:
A::A(const vector<B>& l)
I expose it using
I'd like to call this using:
I registered implicit conversion from
double
andstring
toB
and it flies, that is I can create objectA
usingA([1.0, 'string'])
. This works becauseB
has implicit conversions:B.def(py::init<double>()).def(py::init<std::string>()).def(py::init<>());
and a list of
py::implicitly_convertible<double, B>()...
.Question: How to I add implicit conversion from Python None to use B() when in a list?
The text was updated successfully, but these errors were encountered: