pybind11
pybind11 copied to clipboard
Properly translate C++ exception to Python exception when creating Python buffer from wrapped object
Description
- Refactor exception translation a little - extract inline translation to a callable helper;
- Call the helper if an exception occurs when trying to get a buffer from wrapped object;
- Added the test, which crashes with
Fatal Python errorwithout the fix (unhandlable from within Python) and passes after it is done.
Closes: #2764, #3336
Suggested changelog entry:
* Properly translate C++ exception to Python exception when creating Python buffer from wrapped object
I need to find a block of time to look carefully.
But high-level: There is already too much stuff in internals.h, adding in the exception translator code seems very unfortunate.
pybind11 is poorly factored in general, I'd love to not make it worse, even though it can get tricky sometimes.
Could you please try to move the exception translator code into its own header, maybe pybind11/detail/exception_translators.h?
You'll have to update a couple files when adding a new header. An easy way to pin-point the locations is e.g.:
$ git grep detail/value_and_holder.h
CMakeLists.txt: include/pybind11/detail/value_and_holder.h
tests/extra_python_package/test_files.py: "include/pybind11/detail/value_and_holder.h",
Thanks a lot @EthanSteinberg for the review!