From 1e948cd1a8d41a70bd2880a5ec86207e8fd03225 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Thu, 17 Dec 2020 13:30:18 +0000 Subject: [PATCH 1/4] bpo-42669: Document that `except` rejects nested tuples 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 | 3 ++- Misc/ACKS | 1 + 2 files changed, 3 insertions(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index a55aacccc16dfe..acb92ab608791f 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -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.) If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ diff --git a/Misc/ACKS b/Misc/ACKS index 134f4ea3be874c..621b02affa6593 100644 --- a/Misc/ACKS +++ b/Misc/ACKS @@ -1848,6 +1848,7 @@ Zachary Ware Barry Warsaw Steve Waterbury Bob Watson +Colin Watson David Watson Aaron Watters Henrik Weber From aaa454877393af4eb263fad8af90e11ac4764620 Mon Sep 17 00:00:00 2001 From: "blurb-it[bot]" <43283697+blurb-it[bot]@users.noreply.github.com> Date: Thu, 17 Dec 2020 14:23:17 +0000 Subject: [PATCH 2/4] =?UTF-8?q?=F0=9F=93=9C=F0=9F=A4=96=20Added=20by=20blu?= =?UTF-8?q?rb=5Fit.?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst | 1 + 1 file changed, 1 insertion(+) create mode 100644 Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst b/Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst new file mode 100644 index 00000000000000..24093ddc58c6a3 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst @@ -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 From 9f4986cbfa335c06b730007e2704aa0a76d65ff9 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 20 Dec 2020 18:09:00 +0000 Subject: [PATCH 3/4] Remove redundant parenthesised statement --- Doc/reference/compound_stmts.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/reference/compound_stmts.rst b/Doc/reference/compound_stmts.rst index acb92ab608791f..8da74c79801be9 100644 --- a/Doc/reference/compound_stmts.rst +++ b/Doc/reference/compound_stmts.rst @@ -255,7 +255,7 @@ 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 that is the class or a base class of -the exception object. (Nested tuples are not allowed.) +the exception object. If no except clause matches the exception, the search for an exception handler continues in the surrounding code and on the invocation stack. [#]_ From 80fcc5248066aa1a9276d3386d82bb2e68ce08f4 Mon Sep 17 00:00:00 2001 From: Colin Watson Date: Sun, 20 Dec 2020 18:09:31 +0000 Subject: [PATCH 4/4] Remove blurb Eric V. Smith thinks this isn't a substantive enough change for that, so I'll defer. --- .../next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst | 1 - 1 file changed, 1 deletion(-) delete mode 100644 Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst diff --git a/Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst b/Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst deleted file mode 100644 index 24093ddc58c6a3..00000000000000 --- a/Misc/NEWS.d/next/Documentation/2020-12-17-14-23-16.bpo-42669.fjuDXY.rst +++ /dev/null @@ -1 +0,0 @@ -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