-
-
Notifications
You must be signed in to change notification settings - Fork 1.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
PEP 585 (built-in generics) tracker #4820
Comments
Supported by PyCharm since 2020.2 https://youtrack.jetbrains.com/issue/PY-42418 |
Internally, pytype has actually never distinguished between builtins.list and typing.List, etc. So we should already support this one. |
Test case: from __future__ import annotations
from typing import List
list1: List[str] = []
list2: list[str] = []
reveal_type(list1)
reveal_type(list2) pyre returns:
🎉 This means all type checkers now support this feature and we can start using it in typeshed. 🎉 |
Are we going to have a huge pull request to change |
We should require future PRs to use built-in generics. I am personally in favor of a "big bang" PR after the reshuffling is done. Currently is a good time, since we have nearly no open PRs that could cause conflicts. But I am curious what the other maintainers think. |
How would that turn out for people still using python 3.7 or 3.8? Or should they just pin an older typeshed version? |
I believe mypy actually does not yet support this in type aliases, only lists ( @Hultner this syntax should work in stubs even when it doesn't work at runtime yet. We should confirm that the type checkers actually allow this syntax in stubs when targeting older versions though. |
@JelleZijlstra A quick test seems to work: alias1 = "List[str]"
alias2 = List[str]
alias3 = "list[str]"
alias4 = list[str]
def foo(x: alias4):
for i in x:
reveal_type(i) Correctly reveals |
Reopening because of python/mypy#9980. |
* Remove conventions enforced by black Remove old note about optional default arguments (now part of PEP 484 and enforced by CI) * Recommend to use PEP 585 Cf. #4820 * Try out using collections.abc * Reference mypy bug
The following does not work with mypy:
|
Base classes don't work either. python/mypy#10731 |
Mypy should be fixed on GitHub master. The fixes haven't been released yet, though. |
With the latest mypy release this should be mostly fixed, but as I recall there's still a few issues. |
I am working on a PR for this. |
Generic |
@srittau do you have some opened issue to link me to? I can probably help with this one 🙂 Btw, this works for me on def func(a: type[int]):
reveal_type(a) # N: Revealed type is "Type[builtins.int]"
func(int) # ok
func(str) # E: Argument 1 to "func" has incompatible type "Type[str]"; expected "Type[int]" |
At least the following still fails with mypy 0.920. I didn't test mypy master: class Foo(type[int]): # invalid base class "type"
pass |
And here are a bunch of further errors: https://github.com/python/typeshed/runs/4604434037?check_suite_focus=true #4820 for experiments. |
Can you create mypy issues about any remaining issues and cc me? We can make a mypy point release with the fixes once everything works correctly (there should be no need to wait for a full release). |
python/mypy#10303 seems to be still problematic, but the errors from #4820 are gone with mypy 0.930. 🥳 |
Many pytype errors were output by the CI when I tried to use imports from |
I have opened google/pytype#1096 for the pytype errors. |
As of mypy 0.931 this is now fully supported. |
This issue is supposed to track when we can start to use builtin generics (PEP 585) in typeshed. Support is needed in released versions of:
Also, type aliases are a problem, although this might need
TypeAlias
support (#4913).The text was updated successfully, but these errors were encountered: