[BUG]: pybind11 2.10.0 - error_fetch_and_normalize changes conflicts with PyPy behavior for PyErr_NormalizeException
Nobody has claimed this yet.
- Dominant language
- C++
- Stars
- 18k
- Forks
- 2.3k
- Avg merge
- 5d 17h
- Merged PRs (30d)
- 10
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
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
}
});
Contributor guide
First steps
- Read the whole issue, then the project's contributing guide.
- Comment on the issue to say you are picking it up — it saves two people doing the same work.
- Fork the repository and make your change on a branch.
- Open a pull request that references the issue number.
Research direction
Start with include/pybind11/pytypes.h at the linked error handling around PyErr_NormalizeException, then reproduce the provided C++ example under PyPy 3.8 and CPython. Determine whether PyPy's OSError-to-FileNotFoundError normalization is expected, and document or implement compatibility behavior with regression coverage; done means the mismatch is resolved without breaking the existing CPython behavior.
Written by the indexing model from the issue text.
Assessment
- Tech stack
- cpp, python
- Domain
- api, backend
- Issue type
- Bug
- Difficulty
- 4/5
- Estimated time
- 3-5 days
- Activity status
- Stale
- Clarity
- Needs clarification
- Newbie friendliness
- 25/100