[New-bugs-announce] [issue46967] Type union for except

Henry Schreiner report at bugs.python.org
Wed Mar 9 12:49:02 EST 2022


New submission from Henry Schreiner <henryschreineriii at gmail.com>:

In 3.10 via PEP 604, there was an attempt to use the new union of types where runtime types were previously expected to be a tuple. `isinstance(x, (A, B))` can be written `isinstance(x, A | B)`. Unfortunately, there still is a case were a tuple of types is required: `except (A, B) as err:` cannot be written `except A | B as err:`. I think this should be allowed; it is consistent with isinstance and pattern matching's use of |, and nicely avoids confusion with `except A, B:` which is disallowed for Python 2 reasons; `except A | B`: would be valid.

----------
components: Interpreter Core
messages: 414807
nosy: Henry Schreiner
priority: normal
severity: normal
status: open
title: Type union for except
type: enhancement
versions: Python 3.11

_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue46967>
_______________________________________


More information about the New-bugs-announce mailing list