-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Fix for pep585 with __future__ import #9608
Conversation
I don't think the case you presented is valid Python so mypy does the right thing about reporting error here. |
If I'm not missing something, this should be a valid type alias. It might not be that useful for MyCustomType = dict[str, typing.Optional[tuple[int, float]]
my_var: MyCustomType = {...} |
Sorry it's my miss that I didn't see that the PR is related to PEP585, yeah it should support alias. |
It is not a valid type alias for Python 3.8 and lower, regardless of whether While this is valid code in Python 3.9, we definitely should still complain about this for older Python versions. |
@hauntsaninja I didn't follow the discussion exactly around PEP585 so I might be missing something. However as far as I understand it, the backwards compatibility (until 37) is only dependent on the typechecker understanding it [1]. Type aliases are already supported [2]. Again I might be missing something. [1] https://www.python.org/dev/peps/pep-0585/#id5 |
Maybe I'm missing something too! :-) What I'm trying to say is that mypy should mirror runtime behaviour by complaining about this snippet for Python versions where we get TypeErrors:
There's a difference between a type annotation and a type alias. PEP 563 goes into more detail here. |
Note that once mypy supports PEP 613 (#9404) we should probably also allow |
I think I understand your point now. You're right! I was testing with py39 which is why I didn't recognize the error 🙈 |
Description
Fix PR fixes an issue introduced with #7963. When using
from __future__ import annotations
with py37 and above, the following should pass:Test Plan
I've added some tests to verify that the change works as intended.
--
cc: @TH3CHARLie