-
-
Notifications
You must be signed in to change notification settings - Fork 32k
bpo-42669: Document that except
rejects nested tuples
#23822
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
bpo-42669: Document that except
rejects nested tuples
#23822
Conversation
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.
Doc/reference/compound_stmts.rst
Outdated
@@ -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. (Nested tuples are not allowed.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
With this reworded sentence, I don't think the parenthesized statement is needed.
@@ -0,0 +1 @@ | |||
Explain that :keyword:`except` no longer accepts nested tuples. (This was changed in Python 3.0, but not previously documented.) |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I don't think we need the blurb for this change. It's not substantive enough to be in the News file.
Eric V. Smith thinks this isn't a substantive enough change for that, so I'll defer.
I have made the requested changes; please review again. |
Thanks for making the requested changes! : please review the changes made to this pull request. |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good. Thanks!
@cjwatson: Status check is done, and it's a success ✅ . |
Thanks @cjwatson for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9. |
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]>
GH-23870 is a backport of this pull request to the 3.9 branch. |
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]>
GH-23871 is a backport of this pull request to the 3.8 branch. |
…H-23870) 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]> Co-authored-by: Colin Watson <[email protected]>
…H-23871) 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]> Co-authored-by: Colin Watson <[email protected]>
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
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: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 multipleexcept
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.https://bugs.python.org/issue42669
Automerge-Triggered-By: GH:ericvsmith