]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
bpo-42669: Document that `except` rejects nested tuples (GH-23822) (GH-23871)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Sun, 20 Dec 2020 21:18:40 +0000 (13:18 -0800)
committerGitHub <noreply@github.com>
Sun, 20 Dec 2020 21:18:40 +0000 (16:18 -0500)
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:

    try:
        self.getInputValue()
        return True
    except (InputErrors, SomethingElse):
        return False

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.

Automerge-Triggered-By: GH:ericvsmith
(cherry picked from commit c95f8bc2700b42f4568886505a819816c9b0ba28)

Co-authored-by: Colin Watson <cjwatson@debian.org>
Co-authored-by: Colin Watson <cjwatson@debian.org>
Doc/reference/compound_stmts.rst
Misc/ACKS

index 6900c7ac7d0714603dfd5531f87bd4a942071848..61037d97a0c3cca904e92174079450223d5cba4b 100644 (file)
@@ -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.  [#]_
index 8afc0a8e46d571fd75a8ed6f263a67740de7f7c9..6ae882479d4363ebfb67d10093df15d163c8b5a4 100644 (file)
--- a/Misc/ACKS
+++ b/Misc/ACKS
@@ -1792,6 +1792,7 @@ Zachary Ware
 Barry Warsaw
 Steve Waterbury
 Bob Watson
+Colin Watson
 David Watson
 Aaron Watters
 Henrik Weber