-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[BUG]: Regression from 2.5.0 to 2.6.0: Existance of operator breaks binding of some collections #3600
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
The error message could definitely be improved. The real issue is that it should be an error for where the is_operator is specified or not. When you set Ping @YannickJadoul and @rwgk since you were contributors on that PR. Ultimately seems that the issue is that we can return properly descriptive errors due to our type casters: pybind11/include/pybind11/pytypes.h Line 1611 in 39fbc79
The real issue that this demonstrates is that the setting of the hash function to None can be bypassed. |
Okay, yeah this is entirely user error as only binary operators should has is_operator applied. |
But why does pybind11 then allow this module.def("test_func", []() {
return std::vector<Struct>{{"one"}, {"two"}};
}); or this module.def("test_func", []() {
return Struct{"one"};
}); Both seem to return instances towards Python just fine. If it is a general user error, should it not fail consistently? |
unordered_sets get converted to python sets which require the object to be hashable. This is a quirk in Python that if you define |
I see, thanks for the clarification! If I understand it correctly a by-product of #1853 would be that the error raised in this case would become
instead of the default Unable to convert function return value to a Python type! .... That would indeed have simplified solving this problem a lot. Alternatively it would be great to include that underlying Python exception into the default error message. |
@bluenote10 It's now included as a nested exception. |
Required prerequisites
Problem description
In the following example the
Struct
has a Python binding and is convertible on its own. Alsostd::unordered_set
works in general for build in types. However for the combinationstd::unordered_set<Struct>
the conversion fails at runtime with the error by callingtest_func()
py::is_operator()
in the binding fixes the problem.std::set
, but for anstd::vector
.clang13.0.0
onx86_64
(Ubuntu20.04)Reproducible example code
The text was updated successfully, but these errors were encountered: