From 4193375ed6bcdcaf9ea29754f80962ec7a3f349b Mon Sep 17 00:00:00 2001 From: "Ralf W. Grosse-Kunstleve" Date: Wed, 11 May 2022 23:59:14 -0700 Subject: [PATCH] Change error_already_set() to call pybind11_fail() if the Python error indicator not set. The net result is that a std::runtime_error is thrown instead of error_already_set, but all tests pass as is. --- include/pybind11/pytypes.h | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/include/pybind11/pytypes.h b/include/pybind11/pytypes.h index dbd2c9fe1..912c4a3cb 100644 --- a/include/pybind11/pytypes.h +++ b/include/pybind11/pytypes.h @@ -391,9 +391,8 @@ public: /// RuntimeError("Internal error: ..."). The current Python error indicator will be cleared. error_already_set() : std::runtime_error("") { if (!PyErr_Occurred()) { - m_lazy_what = "Internal error: pybind11::detail::error_already_set called while " - "Python error indicator not set."; - PyErr_SetString(PyExc_RuntimeError, m_lazy_what.c_str()); + pybind11_fail("Internal error: pybind11::detail::error_already_set called while " + "Python error indicator not set."); } PyErr_Fetch(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr()); PyErr_NormalizeException(&m_type.ptr(), &m_value.ptr(), &m_trace.ptr());