Add additional info to TypeError when C++->Python casting fails (#3605)

* Add additional info to TypeInfo when C++->Python casting fails

* Fix typo

* Address reviewer comments
This commit is contained in:
Aaron Gokaslan
2022-01-10 21:18:00 -05:00
committed by GitHub
parent b66328b043
commit ef070f7750
3 changed files with 40 additions and 5 deletions

View File

@@ -996,6 +996,13 @@ protected:
"Python type! The signature was\n\t";
msg += it->signature;
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;
}