-
-
Notifications
You must be signed in to change notification settings - Fork 32.4k
Closed
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error
Description
class MyEG(ExceptionGroup):
"""Holds BaseExceptions without itself being a BaseException."""
oops = MyEG("oops", [KeyboardInterrupt()])
assert isinstance(oops, Exception)
assert not isinstance(oops.exceptions[0], Exception)
I believe that this is a bug tracing to the period when PEP-654 did not intend (Base)ExceptionGroup
to be usable as a parent class; and I think a sufficient fix would be to replace the type-equality check with an isinstance check in:
Lines 740 to 744 in bc390dd
if (cls == PyExc_ExceptionGroup) { | |
if (nested_base_exceptions) { | |
PyErr_SetString(PyExc_TypeError, | |
"Cannot nest BaseExceptions in an ExceptionGroup"); | |
goto error; |
cc @iritkatriel; raised via agronholm/exceptiongroup#40 (comment)
Linked PRs
- gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException #99572
- [3.11] gh-99553: fix bug where an ExceptionGroup subclass can wrap a BaseException (GH-99572) #99580
- gh-99553: add tests for ExceptionGroup wrapping #99615
- [3.11] gh-99553: add tests for ExceptionGroup wrapping (GH-99615) #103435
Metadata
Metadata
Assignees
Labels
3.11only security fixesonly security fixes3.12only security fixesonly security fixesinterpreter-core(Objects, Python, Grammar, and Parser dirs)(Objects, Python, Grammar, and Parser dirs)type-bugAn unexpected behavior, bug, or errorAn unexpected behavior, bug, or error