Skip to content

Commit

Permalink
pythongh-120521: clarify except* documentation to allow tuples (pytho…
Browse files Browse the repository at this point in the history
…n#120523)

Co-authored-by: Jelle Zijlstra <[email protected]>
Co-authored-by: Irit Katriel <[email protected]>
  • Loading branch information
3 people authored and mrahtz committed Jun 30, 2024
1 parent 42064c2 commit a104fc6
Showing 1 changed file with 10 additions and 9 deletions.
19 changes: 10 additions & 9 deletions Doc/reference/compound_stmts.rst
Original file line number Diff line number Diff line change
Expand Up @@ -245,13 +245,12 @@ handler is started. This search inspects the :keyword:`!except` clauses in turn
until one is found that matches the exception.
An expression-less :keyword:`!except` clause, if present, must be last;
it matches any exception.
For an :keyword:`!except` clause with an expression,
that expression is evaluated, and the clause matches the exception
if the resulting object is "compatible" with the exception. An object is
compatible with an exception if the object is 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
of the exception object.

For an :keyword:`!except` clause with an expression, the
expression must evaluate to an exception type or a tuple of exception types.
The raised exception matches an :keyword:`!except` clause whose expression evaluates
to the class or a :term:`non-virtual base class <abstract base class>` of the exception object,
or to a tuple that contains such a class.

If no :keyword:`!except` clause matches the exception,
the search for an exception handler
Expand Down Expand Up @@ -378,8 +377,10 @@ exception group with an empty message string. ::
...
ExceptionGroup('', (BlockingIOError()))

An :keyword:`!except*` clause must have a matching type,
and this type cannot be a subclass of :exc:`BaseExceptionGroup`.
An :keyword:`!except*` clause must have a matching expression; it cannot be ``except*:``.
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*`
in the same :keyword:`try`.
:keyword:`break`, :keyword:`continue` and :keyword:`return`
Expand Down

0 comments on commit a104fc6

Please sign in to comment.