[Python-checkins] bpo-42669: Document that `except` rejects nested tuples (GH-23822)
webhook-mailer at python.org
Sun Dec 20 13:24:18 EST 2020
author: Colin Watson <cjwatson at debian.org>
committer: miss-islington <31488909+miss-islington at users.noreply.github.com>
bpo-42669: Document that `except` rejects nested tuples (GH-23822)
In Python 2, it was possible to use `except` with a nested tuple, and occasionally natural. For example, `zope.formlib.interfaces.InputErrors` is a tuple of several exception classes, and one might reasonably think to do something like this:
except (InputErrors, SomethingElse):
As of Python 3.0, this raises `TypeError: catching classes that do not inherit from BaseException is not allowed` instead: one must instead either break it up into multiple `except` clauses or flatten the tuple. However, the reference documentation was never updated to match this new restriction. Make it clear that the definition is no longer recursive.
diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst
index a55aacccc16df..8da74c79801be 100644
@@ -254,7 +254,8 @@ present, must be last; it matches any exception. For an 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 it is the class or a base class of the exception
-object or a tuple containing an item compatible with the exception.
+object, or a tuple containing an item that is the class or a base class of
+the exception object.
If no except clause matches the exception, the search for an exception handler
continues in the surrounding code and on the invocation stack. [#]_
diff --git a/Misc/ACKS b/Misc/ACKS
index 381aed1009c1a..80e51f93e3aa9 100644
@@ -1849,6 +1849,7 @@ Zachary Ware
More information about the Python-checkins