]> git.ipfire.org Git - thirdparty/Python/cpython.git/commit
bpo-42669: Document that `except` rejects nested tuples (GH-23822)
authorColin Watson <cjwatson@debian.org>
Sun, 20 Dec 2020 18:24:10 +0000 (18:24 +0000)
committerGitHub <noreply@github.com>
Sun, 20 Dec 2020 18:24:10 +0000 (10:24 -0800)
commitc95f8bc2700b42f4568886505a819816c9b0ba28
tree105ca01ea2f7d4b5603135d8a3ec30d354335b98
parentb0398a4b7fb5743f6dbb72ac6b2926e0a0c11498
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:

    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
Doc/reference/compound_stmts.rst
Misc/ACKS