mypy accepts invalid PEP 604 syntax with forward reference #14397
Labels
feature
topic-pep-604
PEP 604 (union | operator)
topic-runtime-semantics
mypy doesn't model runtime semantics correctly
Bug Report
PEP 604 introduced the
|
syntax, however it's not entirely equivalent to theUnion
syntax. Forward references with|
are not supported and result in TypeErrorsTypeError: unsupported operand type(s) for |: 'type' and 'str'
. Mypy doesn't warn the user about this and accepts|
with forward references.To Reproduce
Playground
Expected Behavior
Some kind of error telling me that this syntax is not supported.
Actual Behavior
No errors reported.
Your Environment
mypy.ini
(and other config files): NoneI originally raised this as a discussion in pyright repo. And since then pyright has implemented microsoft/pyright@6eb8467 to detect this incorrect usage of
|
(available in release 1.1.285). I have to admit that documentation on this is a bit murky as I was expecting|
to be equivalent toUnion
and I wasn't the only one, see python/cpython#90015. From what I can gather in this CPython issue runtime won't be changed to make this syntax valid and docs should be changed instead (but neither happened yet).The text was updated successfully, but these errors were encountered: