summaryrefslogtreecommitdiffstats
path: root/Doc
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2024-06-19 19:07:04 (GMT)
committerGitHub <noreply@github.com>2024-06-19 19:07:04 (GMT)
commitadef569278d5f81a0a689c1b086bf819ffea20fd (patch)
tree19d844944eb6452505542e3b9273def720b9ce6b /Doc
parentae04b6f63640606a3212c9da21b87ebc374136e1 (diff)
downloadcpython-adef569278d5f81a0a689c1b086bf819ffea20fd.zip
cpython-adef569278d5f81a0a689c1b086bf819ffea20fd.tar.gz
cpython-adef569278d5f81a0a689c1b086bf819ffea20fd.tar.bz2
[3.13] gh-120521: clarify except* documentation to allow tuples (GH-120523) (#120750)
(cherry picked from commit 58b3f111767148e9011ccd52660e208f0c834b2a) Co-authored-by: Danny Yang <yangdanny97@users.noreply.github.com> Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com> Co-authored-by: Irit Katriel <1055913+iritkatriel@users.noreply.github.com>
Diffstat (limited to 'Doc')
-rw-r--r--Doc/reference/compound_stmts.rst19
1 files changed, 10 insertions, 9 deletions
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index 42cca06..8181b97 100644
--- a/Doc/reference/compound_stmts.rst
+++ b/Doc/reference/compound_stmts.rst
@@ -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
@@ -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`