Closed
Description
Bug Report
In a stub file, with --python-version=3.9
, mypy emits false positive errors for the following type aliases:
from typing import Callable
from typing_extensions import TypeAlias
X = int | Callable[[], str | bool]
XX: TypeAlias = int | Callable[[], str | bool]
Y = int | Callable[[str | bool], str]
YY: TypeAlias = int | Callable[[str | bool], str]
For all of these, mypy's error message is:
error: Unsupported left operand type for | ("Type[str]") [operator]
Note that this snippet works fine in a .py
or .pyi
file with --python-version 3.10
. It's only --python-version 3.9
with a .pyi
file that has the bug.
To Reproduce
cd
into an up-to-date local clone of mypy with an editable install.- Copy the above snippet into a
test.pyi
file. - Run
mypy test.pyi --python-version 3.9
Expected Behavior
No error should be emitted. PEP 604 syntax should be legal in stub files, even with --python-version 3.9
.
Actual Behavior
False-positive errors are emitted.
Your Environment
- Mypy version used: c660354
- Mypy command-line flags:
--python-version 3.9
- Python version used: 3.10
Cc. @ilevkivskyi (x-ref #12393).