diff --git a/common/pybindings.cc b/common/pybindings.cc index b6d5e48a..8f824f1e 100644 --- a/common/pybindings.cc +++ b/common/pybindings.cc @@ -86,7 +86,13 @@ template <> struct string_converter PYBIND11_MODULE(MODULE_NAME, m) { - py::register_exception(m, "PyExc_AssertionError"); + py::register_exception_translator([](std::exception_ptr p) { + try { + if (p) std::rethrow_exception(p); + } catch (const assertion_failure &e) { + PyErr_SetString(PyExc_AssertionError, e.what()); + } + }); using namespace PythonConversion;