-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
False-positive error when using Callable
in a PEP 604 type alias in a stub file with --python-version=3.9
#14158
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
cc @JukkaL who recently worked on this. |
Question: I have this issue in Python 3.8 in a normal from __future__ import annotations
from typing import TYPE_CHECKING, Callable
from poetry.console.application import Application
if TYPE_CHECKING:
import sys
from poetry.poetry import Poetry
if sys.version_info >= (3, 10):
from typing import TypeAlias
else:
from typing_extensions import TypeAlias
ApplicationFactory: TypeAlias = 'Callable[[Poetry | None], Application]'
PoetryFactory: TypeAlias = 'Callable[[str | None], Poetry]' Is this intended behavior for 3.8 with |
@adam-grant-hendry that's correct behaviour from mypy. It'll fail at runtime on Python <3.10 if you don't stringify the alias, even with
|
Excellent, thank you for confirming! Glad to know I did this properly 😃 |
Uh oh!
There was an error while loading. Please reload this page.
Bug Report
In a stub file, with
--python-version=3.9
, mypy emits false positive errors for the following type aliases:For all of these, mypy's error message is:
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.test.pyi
file.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
--python-version 3.9
Cc. @ilevkivskyi (x-ref #12393).
The text was updated successfully, but these errors were encountered: