gh-120521: clarify except* documentation to allow tuples (#120523)

Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
This commit is contained in:
Danny Yang 2024-06-19 14:49:00 -04:00 committed by GitHub
parent d484383861
commit 58b3f11176
No known key found for this signature in database
GPG key ID: B5690EEEBB952194

View file

@ -245,13 +245,12 @@ handler is started. This search inspects the :keyword:`!except` clauses in turn
until one is found that matches the exception. until one is found that matches the exception.
An expression-less :keyword:`!except` clause, if present, must be last; An expression-less :keyword:`!except` clause, if present, must be last;
it matches any exception. it matches any exception.
For an :keyword:`!except` clause with an expression,
that expression is evaluated, and the clause matches the exception For an :keyword:`!except` clause with an expression, the
if the resulting object is "compatible" with the exception. An object is expression must evaluate to an exception type or a tuple of exception types.
compatible with an exception if the object is the class or a The raised exception matches an :keyword:`!except` clause whose expression evaluates
:term:`non-virtual base class <abstract base class>` of the exception object, to the class or a :term:`non-virtual base class <abstract base class>` of the exception object,
or a tuple containing an item that is the class or a non-virtual base class or to a tuple that contains such a class.
of the exception object.
If no :keyword:`!except` clause matches the exception, If no :keyword:`!except` clause matches the exception,
the search for an exception handler the search for an exception handler
@ -378,8 +377,10 @@ exception group with an empty message string. ::
... ...
ExceptionGroup('', (BlockingIOError())) ExceptionGroup('', (BlockingIOError()))
An :keyword:`!except*` clause must have a matching type, An :keyword:`!except*` clause must have a matching expression; it cannot be ``except*:``.
and this type cannot be a subclass of :exc:`BaseExceptionGroup`. Furthermore, this expression cannot contain exception group types, because that would
have ambiguous semantics.
It is not possible to mix :keyword:`except` and :keyword:`!except*` It is not possible to mix :keyword:`except` and :keyword:`!except*`
in the same :keyword:`try`. in the same :keyword:`try`.
:keyword:`break`, :keyword:`continue` and :keyword:`return` :keyword:`break`, :keyword:`continue` and :keyword:`return`