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

@@ -299,4 +299,12 @@ TEST_SUBMODULE(exceptions, m) {
std::throw_with_nested(std::runtime_error("Outer Exception"));
}
});
m.def("error_already_set_what", [](const py::object &exc_type, const py::object &exc_value) {
PyErr_SetObject(exc_type.ptr(), exc_value.ptr());
std::string what = py::error_already_set().what();
bool py_err_set_after_what = (PyErr_Occurred() != nullptr);
PyErr_Clear();
return py::make_tuple(std::move(what), py_err_set_after_what);
});
}