[issue42669] "except" documentation still suggests nested tuples are allowed

New submission from Colin Watson <cjwatson@users.sourceforge.net>: 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 (this is real code used in several places in https://git.launchpad.net/launchpad): 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. The change was mentioned in https://bugs.python.org/issue2380 and seems to have been intentional: I'm not requesting that the previous behaviour be restored, since it's a fairly rare porting issue and by now well-established in Python 3. However, the relevant sentences of documentation in https://docs.python.org/2/reference/compound_stmts.html#try and https://docs.python.org/3/reference/compound_stmts.html#the-try-statement are identical aside from punctuation, and they both read: 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. I think this admits a recursive reading: I certainly read it that way. It should make it clear that nested tuples are not allowed. ---------- assignee: docs@python components: Documentation messages: 383243 nosy: cjwatson, docs@python priority: normal severity: normal status: open title: "except" documentation still suggests nested tuples are allowed versions: Python 3.10 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

Change by Colin Watson <cjwatson@users.sourceforge.net>: ---------- keywords: +patch pull_requests: +22682 stage: -> patch review pull_request: https://github.com/python/cpython/pull/23822 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

miss-islington <mariatta.wijaya+miss-islington@gmail.com> added the comment: New changeset c95f8bc2700b42f4568886505a819816c9b0ba28 by Colin Watson in branch 'master': bpo-42669: Document that `except` rejects nested tuples (GH-23822) https://github.com/python/cpython/commit/c95f8bc2700b42f4568886505a819816c9b... ---------- nosy: +miss-islington _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +22732 pull_request: https://github.com/python/cpython/pull/23870 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

Change by miss-islington <mariatta.wijaya+miss-islington@gmail.com>: ---------- pull_requests: +22733 pull_request: https://github.com/python/cpython/pull/23871 _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

Eric V. Smith <eric@trueblade.com> added the comment: New changeset 409ce4a09e4f96ca9b251c19f5819205aae9ae34 by Miss Islington (bot) in branch '3.9': bpo-42669: Document that `except` rejects nested tuples (GH-23822) (GH-23870) https://github.com/python/cpython/commit/409ce4a09e4f96ca9b251c19f5819205aae... ---------- nosy: +eric.smith _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

Eric V. Smith <eric@trueblade.com> added the comment: New changeset 81f706d2db0f57c4fdd747df6e0a4cffcbc54704 by Miss Islington (bot) in branch '3.8': bpo-42669: Document that `except` rejects nested tuples (GH-23822) (GH-23871) https://github.com/python/cpython/commit/81f706d2db0f57c4fdd747df6e0a4cffcbc... ---------- _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________

Change by Eric V. Smith <eric@trueblade.com>: ---------- resolution: -> fixed stage: patch review -> resolved status: open -> closed _______________________________________ Python tracker <report@bugs.python.org> <https://bugs.python.org/issue42669> _______________________________________
participants (3)
-
Colin Watson
-
Eric V. Smith
-
miss-islington