Open
Description
Required prerequisites
- Make sure you've read the documentation. Your issue may be addressed there.
- Search the issue tracker and Discussions to verify that this hasn't already been reported. +1 or comment there if it has.
- Consider asking first in the Gitter chat room or in a Discussion.
Problem description
PyPy 3.8 triggers the newly introduced error message
pybind11/include/pybind11/pytypes.h
Lines 459 to 469 in 59f03ee
MISMATCH of original and normalized active exception types: ORIGINAL OSError REPLACED BY FileNotFoundError: [Errno 2] No such file or directory: 'this_file_does_not_exist'
In PyPy, PyErr_NormalizeException
causes the "raw" OSError to be normalized into FileNotFoundError. Which seems fair enough.
It's unclear to me whether PyPy is doing something "naughty" here that violates the expectations set by CPython, or if this new exception handling code is just imposing an expectation that doesn't hold for PyPy. As such I don't know if simply disabling that test is appropriate for PyPy.
CPython does not make the same substitution. There is no error (and the code behaves correctly) with pybind11 2.9.
Reproducible example code
m.def("test_pypy_oserror_normalization", []() {
// We want to do "with suppress(FileNotFoundError): open(f)" in C++
try {
py::module_::import("io").attr("open")("this_file_does_not_exist", "r");
} catch (const py::error_already_set &e) {
// FileNotFoundError
}
});