PEP 654: Clarifications after python-dev review (#1838)

- subgroup returns None for empty.
- except *(TypeError, ExceptionGroup) is forbidden.
This commit is contained in:
Irit Katriel 2021-02-24 01:39:29 +00:00 committed by GitHub
parent 05fe23f12b
commit 13be7c414f
No known key found for this signature in database
GPG Key ID: 4AEE18F83AFDEB23
1 changed files with 8 additions and 1 deletions

View File

@ -186,7 +186,9 @@ contains only those exceptions for which the condition is true:
Empty nested ``ExceptionGroups`` are omitted from the result, as in the Empty nested ``ExceptionGroups`` are omitted from the result, as in the
case of ``ExceptionGroup("three")`` in the example above. The original ``eg`` case of ``ExceptionGroup("three")`` in the example above. If none of the
leaf exceptions match the condition, ``subgroup`` returns ``None`` rather
than an empty ``ExceptionGroup``. The original ``eg``
is unchanged by ``subgroup``, but the value returned is not necessarily a full is unchanged by ``subgroup``, but the value returned is not necessarily a full
new copy. Leaf exceptions are not copied, nor are ``ExceptionGroups`` which are new copy. Leaf exceptions are not copied, nor are ``ExceptionGroups`` which are
fully contained in the result. When it is necessary to partition an fully contained in the result. When it is necessary to partition an
@ -860,6 +862,11 @@ with ``except*`` because the latter is ambiguous:
except *ExceptionGroup: # <- Runtime error except *ExceptionGroup: # <- Runtime error
pass pass
try:
...
except *(TypeError, ExceptionGroup): # <- Runtime error
pass
An empty "match anything" ``except*`` block is not supported as its meaning may An empty "match anything" ``except*`` block is not supported as its meaning may
be confusing: be confusing: