Uh oh!
There was an error while loading.Please reload this page.
- Notifications
You must be signed in to change notification settings - Fork34.1k
Closed
Description
Currently,contextlib.suppress does not successfully suppress exceptions that are wrapped within anExceptionGroup.
In other words, this works:
def raise_ve(): raise ValueError("ve")with suppress(ValueError): raise_ve()while this doesn't:
def raise_ve_eg(): raise ExceptionGroup("eg", [ValueError("ve")])with suppress(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:
def raise_ve_eg3(): raise ExceptionGroup("eg", [ValueError("ve1"), KeyError("ke"), ValueError("ve2")])with suppress(ValueError): raise_ve_eg3()should raise anExceptionGroup with theKeyError("ke") only, as we suppressed ValueError instances.