We read every piece of feedback, and take your input very seriously.
To see all available qualifiers, see our documentation.
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
Just upgrade from 2.2.4 to 2.3.0, nothing else changed, but got error when import package in python as below
libc++abi.dylib: terminating with uncaught exception of type pybind11::error_already_set: TypeError: __int__ returned non-int (type str)
it seems enum definition not supported. eg.
enum class A: char { First='1', Second = '2', }
The text was updated successfully, but these errors were encountered:
Hi, I have tried a work-around by modify method "int" in pybind11.h
@line 1555 ~ 1558
def("__int__", [](Type value) { return int(static_cast<Scalar>(value)); }); #if PY_MAJOR_VERSION < 3 def("__long__", [](Type value) { return long(static_cast<Scalar>(value)); }); #endif
but it smells not well.
Is there any better solutions? @wjakob
Sorry, something went wrong.
I've also spotted it when upgrading to 2.3.0. But the only problem I came across was using such enums as a default arg. For example:
#include <pybind11/pybind11.h> namespace py = pybind11; enum class X : char { X1, X2 }; bool foo(X x) { return x == X::X1; } PYBIND11_MODULE(example, m) { py::enum_<X>(m, "X").value("X1", X::X1).value("X2", X::X2); m.def("foo", &foo, py::arg("x")=X::X1); }
In my case the simplest workaround is to change char to signed char (or unsigned char).
char
signed char
unsigned char
Successfully merging a pull request may close this issue.
Just upgrade from 2.2.4 to 2.3.0, nothing else changed, but got error when import package in python as below
libc++abi.dylib: terminating with uncaught exception of type pybind11::error_already_set: TypeError: __int__ returned non-int (type str)
it seems enum definition not supported. eg.
enum class A: char { First='1', Second = '2', }
The text was updated successfully, but these errors were encountered: