Skip to content

Commit 81f706d

Browse files
bpo-42669: Document that except rejects nested tuples (GH-23822) (GH-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]>
1 parent b01091a commit 81f706d

File tree

2 files changed

+3
-1
lines changed

2 files changed

+3
-1
lines changed

Doc/reference/compound_stmts.rst

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -254,7 +254,8 @@ present, must be last; it matches any exception. For an except clause with an
254254
expression, that expression is evaluated, and the clause matches the exception
255255
if the resulting object is "compatible" with the exception. An object is
256256
compatible with an exception if it is the class or a base class of the exception
257-
object or a tuple containing an item compatible with the exception.
257+
object, or a tuple containing an item that is the class or a base class of
258+
the exception object.
258259

259260
If no except clause matches the exception, the search for an exception handler
260261
continues in the surrounding code and on the invocation stack. [#]_

Misc/ACKS

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1792,6 +1792,7 @@ Zachary Ware
17921792
Barry Warsaw
17931793
Steve Waterbury
17941794
Bob Watson
1795+
Colin Watson
17951796
David Watson
17961797
Aaron Watters
17971798
Henrik Weber

0 commit comments

Comments
 (0)