-
-
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
A type created with type(...)
is not valid as a type
#8897
Comments
This is generally too dynamic for mypy to understand. It would probably be quite difficult to make it work in mypy except in simple cases where all the arguments are static. |
What about the following? class X: pass
x: X # works
Y = cast(type, X)
y: Y # is not valid as a type
Z: type = X
z: Z # is not valid as a type It would be cool to have at least one way to tell mypy that some object is actually a type, e.g. |
But then using that object in an annotation is useless. You could just as well say ‘z: object’. |
Also in my example |
Mypy doesn’t special-case calls to type() that way. To me this feels like something too dynamic to expect mypy to understand, sorry. And IIRC Type[str] has a different meaning (the type of ‘str’?). |
For visitors of this issue, there’s another related discussion here. |
It seems that types created using
type(...)
are not valid as type annotations.The result is:
Is this considered a bug or an intentional design decision? Is there a way to use this kind of type as a type annotation?
Python 3.7.5, MyPy 0.770.
The text was updated successfully, but these errors were encountered: