bpo-42669: Document that except rejects nested tuples#23822
Merged
miss-islington merged 4 commits intopython:masterfrom Dec 20, 2020
Merged
bpo-42669: Document that except rejects nested tuples#23822miss-islington merged 4 commits intopython:masterfrom
except rejects nested tuples#23822miss-islington merged 4 commits intopython:masterfrom
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.
ericvsmith
reviewed
Dec 20, 2020
Doc/reference/compound_stmts.rst
Outdated
| 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.) |
Member
There was a problem hiding this comment.
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.) No newline at end of file | |||
Member
There was a problem hiding this comment.
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.
Contributor
Author
|
I have made the requested changes; please review again. |
|
Thanks for making the requested changes! : please review the changes made to this pull request. |
Contributor
|
@cjwatson: Status check is done, and it's a success ✅ . |
Contributor
|
Thanks @cjwatson for the PR 🌮🎉.. I'm working now to backport this PR to: 3.8, 3.9. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
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>
|
GH-23870 is a backport of this pull request to the 3.9 branch. |
miss-islington
pushed a commit
to miss-islington/cpython
that referenced
this pull request
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>
|
GH-23871 is a backport of this pull request to the 3.8 branch. |
ericvsmith
pushed a commit
that referenced
this pull request
Dec 20, 2020
…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 <cjwatson@debian.org> Co-authored-by: Colin Watson <cjwatson@debian.org>
ericvsmith
pushed a commit
that referenced
this pull request
Dec 20, 2020
…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 <cjwatson@debian.org> Co-authored-by: Colin Watson <cjwatson@debian.org>
adorilson
pushed a commit
to adorilson/cpython
that referenced
this pull request
Mar 13, 2021
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
In Python 2, it was possible to use
exceptwith a nested tuple, and occasionally natural. For example,zope.formlib.interfaces.InputErrorsis 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 allowedinstead: one must instead either break it up into multipleexceptclauses 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