-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
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
False-positive errors when using type[T]
(or Type[T]
) in a PEP 604 type alias
#12392
Comments
type[T]
(or Type[T]`) in a PEP 604 type aliastype[T]
(or Type[T]
) in a PEP 604 type alias
I have encountered the following
It looks like the same issue? |
This issue seems to exist for any runtime evaluation of def f() -> type:
return type[int] # error: Value of type "Type[type]" is not indexable This still happens when using the |
Hm, on current master, two of them work, but other two (with lowercase
cc @JukkaL who recently worked on this. |
Hi, Thanks for working on mypy and the related tools! Is this bug really fixed though? With the attached file (renamed with a .py extension) I get the following:
If I use Union to define the IPClass alias, it works just fine. If I put the union - either using Union or the
|
@ppentchev, there hasn't yet been a mypy release that includes the fix. Are you testing with the mypy master branch? |
@AlexWaygood Thanks for the lightning-fast reply! I had actually realized that, and I just came back to leave a "sorry for the noise, I just tested with the Git version and it works just fine!" comment... and you had already replied :) Thanks again for all your work, and apologies! |
Bug Report
The following two snippets (one using
builtins.type
, the other usingtyping.Type
) both work fine at runtime on 3.10+. They should be accepted as valid type alias definitions on Python 3.10+ (and should be accepted in stub files regardless of Python version). However, mypy raises false-positive errors for both. The errors do not go away if you usetyping.TypeAlias
:The order of the types in the union makes no difference when using
type[T]
: the following two variants still produce errors:However, the order of the types in the union does matter if you're using
typing.Type[T]
:Interestingly, the bug can only be reproduced if
type
orType
is the outermost object in the type alias. Neither of the following two snippets causes mypy errors:Mypy is also happy with
type[T]
orType[T]
being used in old-styletyping.Union
type aliases:To Reproduce
Mypy playground link here.
Expected Behavior
No error should be reported.
Cc. @JelleZijlstra
The text was updated successfully, but these errors were encountered: