Move PyErr_NormalizeException() up a few lines (#3971)

* Add error_already_set_what what tests, asserting the status quo.

* Move PyErr_NormalizeException() up a few lines.

* @pytest.mark.skipif("env.PYPY") from PR #1895 is required even for this much simpler PR

* Move PyException_SetTraceback() with PyErr_NormalizeException() as suggested by @skylion007

* Insert a std::move() as suggested by @skylion007
This commit is contained in:
Ralf W. Grosse-Kunstleve
2022-05-25 21:44:55 -07:00
committed by GitHub
parent 2d4a20c8cb
commit 2c549eb7aa
3 changed files with 63 additions and 6 deletions

View File

@@ -478,6 +478,11 @@ PYBIND11_NOINLINE std::string error_string() {
error_scope scope; // Preserve error state
PyErr_NormalizeException(&scope.type, &scope.value, &scope.trace);
if (scope.trace != nullptr) {
PyException_SetTraceback(scope.value, scope.trace);
}
std::string errorString;
if (scope.type) {
errorString += handle(scope.type).attr("__name__").cast<std::string>();
@@ -487,12 +492,6 @@ PYBIND11_NOINLINE std::string error_string() {
errorString += (std::string) str(scope.value);
}
PyErr_NormalizeException(&scope.type, &scope.value, &scope.trace);
if (scope.trace != nullptr) {
PyException_SetTraceback(scope.value, scope.trace);
}
#if !defined(PYPY_VERSION)
if (scope.trace) {
auto *trace = (PyTracebackObject *) scope.trace;