-
Notifications
You must be signed in to change notification settings - Fork 2.2k
[BUGFIX] Fixing pybind11::error_already_set.matches to also work with exception subclasses #1715
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
[BUGFIX] Fixing pybind11::error_already_set.matches to also work with exception subclasses #1715
Conversation
8d33c94
to
5664010
Compare
Can you make that example that shows the error a test case, so that we have a test that fails without this PR, but works with it? |
Good point; will do! |
5664010
to
b3e190c
Compare
@bstaletic I already rebased. Any idea why that the docs fail to build? Something seems wrong with sphinx/doxygen/breathe? |
I'm guessing some python library got updated and broke things... |
Aha! breathe-doc/breathe#411 broke the build because pybind requires Two options:
|
Great; thanks for figuring that out. But then it's got nothing to do with this PR, luckily :-)
I think that should work, since |
…ybind11::error_already_set.matches
b3e190c
to
1e0ec0e
Compare
Done, I think; let's see if all tests now work. I also had to fix the old test on |
All green! Thanks for the CI investigation and fix, @bstaletic! @wjakob, if you!d be thinking about a new patch release, this one might be interesting? |
Nice catch -- merged! |
ImportError is caused by a bug in an older pybind11 version which does not allow exception subclasses in error_already_set::matches. See pybind/pybind11#1715. PiperOrigin-RevId: 292511528 Change-Id: I494fd029728b304ab1add94713e01544c20db6fe
The
error_already_set.matches
implementation (introduced in #772) forwards the two exception types in the wrong order as arguments toPyErr_GivenExceptionMatches
. This PR fixes that (and renames the parameter/argument fromex
toexc
to explicitly match the Python documentation).The reason this bug didn't cause a lot of harm and wasn't notice before is that the problem is only noticeable when matching to an exception base class (otherwise, the order of the arguments does not end up mattering).
This demonstrates the error, as
ModuleNotFound
error is a subclass ofImportError
in Python >= 3.6: