Skip to content
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

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

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 cjwatson@debian.org

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 <cjwatson@debian.org>
@miss-islington
Copy link
Contributor Author

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

@ericvsmith ericvsmith merged commit 409ce4a into python:3.9 Dec 20, 2020
@miss-islington miss-islington deleted the backport-c95f8bc-3.9 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