Skip to content

Commit 409ce4a

Browse files
bpo-42669: Document that except rejects nested tuples (GH-23822) (GH-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]>
1 parent 40b4c40 commit 409ce4a

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
@@ -1829,6 +1829,7 @@ Zachary Ware
18291829
Barry Warsaw
18301830
Steve Waterbury
18311831
Bob Watson
1832+
Colin Watson
18321833
David Watson
18331834
Aaron Watters
18341835
Henrik Weber

0 commit comments

Comments
 (0)