You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
As we scale up our use of except* and ExceptionGroups, we've noticed that isinstance() checks get noticeably more clumsy:
# often the isinstance is implicit due to an except-statementnot_found=isinstance(err, HTTPError) anderr.status_code==404# becomesifisinstance(err, BaseExceptionGroup):
# often we'd want .split() to do something with the other case, but for simplicity:not_found=err.subgroup(lambdae: isinstance(e, HTTPError) ande.status_code==404) isnotNoneelse:
# as above
Obviously we use except T as err: or except* T ... wherever possible, but there are cases where we need to inspect metadata beyond the error type and duplicating the logic often gets messy.
By adding .subgroup() and .split() methods to BaseException, which for non-groups act as if the exception was wrapped in a single-member group, we can avoid duplication and write only the necessarily-more-complicated code for groups to cover both cases.
(opening issue as discussed with @gpshead and @njsmith elsewhere)
The text was updated successfully, but these errors were encountered:
As we scale up our use of
except*
andExceptionGroups
, we've noticed thatisinstance()
checks get noticeably more clumsy:Obviously we use
except T as err:
orexcept* T ...
wherever possible, but there are cases where we need to inspect metadata beyond the error type and duplicating the logic often gets messy.By adding
.subgroup()
and.split()
methods toBaseException
, which for non-groups act as if the exception was wrapped in a single-member group, we can avoid duplication and write only the necessarily-more-complicated code for groups to cover both cases.(opening issue as discussed with @gpshead and @njsmith elsewhere)
The text was updated successfully, but these errors were encountered: