-
Notifications
You must be signed in to change notification settings - Fork 2.2k
Change base parameter type in register_exception and exception constructor from PyObject* to handle #2467
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
Conversation
…ctor from PyObject* to handle
So this is a breaking change. On top of that, you mentioned using |
Huh, I thought you could. There's also an implicit conversion, so it's a bit weird that this doesn't work? pybind11/include/pybind11/pytypes.h Line 179 in 3bd0d7a
Yes, but it's not there, yet. So indeed, let's link to #2388. |
It's the opposite way that doesn't work implicitly, |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right, I was mixing things up with py::object(py::handle)
, which doesn't work.
Anyway, this looks good now.
Does this mean that now it is possible to do:
i.e. make a hierarchy of exceptions, starting with python ones and continuing into the ones defined on the C++ side? If not, how can this be achieved? |
@michalsustr Not sure, actually. I would think it has always worked, but that before, you'd need to say |
@michalsustr (and others), I quickly checked, and this seems to already work: #include <pybind11/pybind11.h>
namespace py = pybind11;
class X : public std::runtime_error {};
class Y : public std::runtime_error {};
PYBIND11_MODULE(example, m)
{
auto exceptionA = py::register_exception<X>(m, "ExceptionA", PyExc_RuntimeError);
py::register_exception<Y>(m, "ExceptionB", exceptionA.ptr());
} So this PR just removes the need to add |
Follow-up of #2465. This should be the same, but is the pybind11 alternative, rather than a raw C API type.