Skip to content

Commit c95f8bc

Browse files
authored
bpo-42669: Document that except rejects nested tuples (GH-23822)
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
1 parent b0398a4 commit c95f8bc

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
@@ -1849,6 +1849,7 @@ Zachary Ware
18491849
Barry Warsaw
18501850
Steve Waterbury
18511851
Bob Watson
1852+
Colin Watson
18521853
David Watson
18531854
Aaron Watters
18541855
Henrik Weber

0 commit comments

Comments
 (0)