Skip to content

Commit ce18721

Browse files
authored
Ensure TypeError use raise_from for C++->Python overload res. (#3671)
1 parent 978617f commit ce18721

File tree

1 file changed

+7
-0
lines changed

1 file changed

+7
-0
lines changed

include/pybind11/pybind11.h

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -988,6 +988,13 @@ class cpp_function : public function {
988988
}
989989

990990
append_note_if_missing_header_is_suspected(msg);
991+
#if PY_VERSION_HEX >= 0x03030000
992+
// Attach additional error info to the exception if supported
993+
if (PyErr_Occurred()) {
994+
raise_from(PyExc_TypeError, msg.c_str());
995+
return nullptr;
996+
}
997+
#endif
991998
PyErr_SetString(PyExc_TypeError, msg.c_str());
992999
return nullptr;
9931000
}

0 commit comments

Comments
 (0)