From ce18721d830a9deb8cf1883b513bcb8f98090c35 Mon Sep 17 00:00:00 2001 From: Aaron Gokaslan Date: Mon, 31 Jan 2022 15:13:05 -0500 Subject: [PATCH] Ensure TypeError use raise_from for C++->Python overload res. (#3671) --- include/pybind11/pybind11.h | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/include/pybind11/pybind11.h b/include/pybind11/pybind11.h index fd60ea29f2..ede35e1867 100644 --- a/include/pybind11/pybind11.h +++ b/include/pybind11/pybind11.h @@ -988,6 +988,13 @@ class cpp_function : public function { } 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; }