Skip to content
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

type not generic when running with Python < 3.9 #10303

Closed
srittau opened this issue Apr 9, 2021 · 5 comments · Fixed by #10766
Closed

type not generic when running with Python < 3.9 #10303

srittau opened this issue Apr 9, 2021 · 5 comments · Fixed by #10766
Labels
bug mypy got something wrong

Comments

@srittau
Copy link
Contributor

srittau commented Apr 9, 2021

Bug Report

Please consider the following stub file:

x: dict[str, str]
y: type[str]

When checking it with mypy 0.820+dev.1e96f1df48a6e06ba598fa8230b96671b206cba0 and Python 3.9.4, it passes. Using Python 3.8.9 on the other hand, produces the following output:

foo.pyi:2: error: "type" expects no type arguments, but 1 given

It's weird that generic dict works, but generic type doesn't. (Although I'd expect both to work with any Python version.)

This came up during python/typeshed#5192.

@srittau srittau added the bug mypy got something wrong label Apr 9, 2021
JukkaL added a commit that referenced this issue Jul 5, 2021
This fixes these issues:

* Allow variable-length tuple (tuple[int, ...]) in type aliases
* Allow generic built-in types (e.g. list[int]) in stubs in all Python versions

Fixes #9980. Fixes #10303. Fixes #10731.
@srittau
Copy link
Contributor Author

srittau commented Dec 22, 2021

@JukkaL This doesn't seem to fixed in mypy 0.930:

$ mypy --version
mypy 0.930
$ cat foo.pyi 
x: dict[str, str]
y: type[str]
$ mypy --python-version=3.9 foo.pyi 
Success: no issues found in 1 source file
$ mypy --python-version=3.8 foo.pyi 
foo.pyi:2: error: "type" expects no type arguments, but 1 given
Found 1 error in 1 file (checked 1 source file)

(I tested it with both Python 3.9.6 and 3.6.14.)

@AlexWaygood
Copy link
Member

AlexWaygood commented Dec 28, 2021

@JukkaL This doesn't seem to fixed in mypy 0.930:

Interestingly, it appears to be fixed for .py files, but not for .pyi files. This, in a .py file, will pass using Python 3.7:

from __future__ import annotations
foo: type[str]

But this, in a .pyi file, fails using Python <= 3.8:

foo: type[str]

Many similar errors can be found in the CI output for python/typeshed#6681.

@AlexWaygood
Copy link
Member

Cc. @sobolevn

@sobolevn
Copy link
Member

sobolevn commented Dec 29, 2021

Sorry, I cannot not reopen issues, but here's my PR: #11863

@hauntsaninja
Copy link
Collaborator

Thanks to sobolevn this should be fixed for pyi with old Pythons!

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug mypy got something wrong
Projects
None yet
Development

Successfully merging a pull request may close this issue.

4 participants