Skip to content

Commit 58b3f11

Browse files
yangdanny97JelleZijlstrairitkatriel
authored
gh-120521: clarify except* documentation to allow tuples (#120523)
Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Irit Katriel <[email protected]>
1 parent d484383 commit 58b3f11

File tree

1 file changed

+10
-9
lines changed

1 file changed

+10
-9
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 10 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -245,13 +245,12 @@ handler is started. This search inspects the :keyword:`!except` clauses in turn
245245
until one is found that matches the exception.
246246
An expression-less :keyword:`!except` clause, if present, must be last;
247247
it matches any exception.
248-
For an :keyword:`!except` clause with an expression,
249-
that expression is evaluated, and the clause matches the exception
250-
if the resulting object is "compatible" with the exception. An object is
251-
compatible with an exception if the object is the class or a
252-
:term:`non-virtual base class <abstract base class>` of the exception object,
253-
or a tuple containing an item that is the class or a non-virtual base class
254-
of the exception object.
248+
249+
For an :keyword:`!except` clause with an expression, the
250+
expression must evaluate to an exception type or a tuple of exception types.
251+
The raised exception matches an :keyword:`!except` clause whose expression evaluates
252+
to the class or a :term:`non-virtual base class <abstract base class>` of the exception object,
253+
or to a tuple that contains such a class.
255254

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

381-
An :keyword:`!except*` clause must have a matching type,
382-
and this type cannot be a subclass of :exc:`BaseExceptionGroup`.
380+
An :keyword:`!except*` clause must have a matching expression; it cannot be ``except*:``.
381+
Furthermore, this expression cannot contain exception group types, because that would
382+
have ambiguous semantics.
383+
383384
It is not possible to mix :keyword:`except` and :keyword:`!except*`
384385
in the same :keyword:`try`.
385386
:keyword:`break`, :keyword:`continue` and :keyword:`return`

0 commit comments

Comments
 (0)