diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index fd60ea29..ede35e18 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -988,6 +988,13 @@ protected: } append_note_if_missing_header_is_suspected(msg); +#if PY_VERSION_HEX >= 0x03030000 + // Attach additional error info to the exception if supported + if (PyErr_Occurred()) { + raise_from(PyExc_TypeError, msg.c_str()); + return nullptr; + } +#endif PyErr_SetString(PyExc_TypeError, msg.c_str()); return nullptr; }