Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork32.1k
Closed
Description
Currently,contextlib.suppress
does not successfully suppress exceptions that are wrapped within anExceptionGroup
.
In other words, this works:
defraise_ve():raiseValueError("ve")withsuppress(ValueError):raise_ve()
while this doesn't:
defraise_ve_eg():raiseExceptionGroup("eg", [ValueError("ve")])withsuppress(ValueError):raise_ve_eg()
The user's intent is to suppress the latter case, too. It should work just as well, removingValueError
instances from the exception group. If it ends up empty, nothing gets raised. Otherwise, anExceptionGroup
should be re-raised with the remaining exceptions. For instance:
defraise_ve_eg3():raiseExceptionGroup("eg", [ValueError("ve1"),KeyError("ke"),ValueError("ve2")])withsuppress(ValueError):raise_ve_eg3()
should raise anExceptionGroup
with theKeyError("ke")
only, as we suppressed ValueError instances.