Skip to content

[3.8] bpo-42669: Document that except rejects nested tuples (GH-23822) #23871

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Merged
merged 1 commit into from
Dec 20, 2020

Conversation

miss-islington
Copy link
Contributor

@miss-islington miss-islington commented Dec 20, 2020

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 c95f8bc)

Co-authored-by: Colin Watson [email protected]

https://bugs.python.org/issue42669

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 c95f8bc)

Co-authored-by: Colin Watson <[email protected]>
@miss-islington
Copy link
Contributor Author

@cjwatson: Status check is done, and it's a success ✅ .

@miss-islington
Copy link
Contributor Author

@cjwatson: Status check is done, and it's a success ✅ .

@ericvsmith ericvsmith merged commit 81f706d into python:3.8 Dec 20, 2020
@miss-islington miss-islington deleted the backport-c95f8bc-3.8 branch December 20, 2020 21:18
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

5 participants