-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Why do I need annotations for an empty list or dictionary #922
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
Comments
Because a lot of people will guess "Hey, mypy infers the types of my lists!", while it really doesn't. Crystal does the exact same thing. |
From my point of view, if mypy is an optional type checker then it should stay out of the way unless you explicitly define types. I have no idea what the python3.5 spec says about this though. |
IIRC mypy does stay out of your way until you start annotating a function, and then it complains for every single issue in the function. The granularity is rather poor for global code however. |
There are two related things:
|
See also #1055. For some simple cases involving local variables this has now been solved. |
Great :) thanks for the fix. |
Closing this as this is resolved for most cases that we are planning to support. Feel free to file new issues for particular examples where type inference still fails. |
Every time I do
or
mypy complains and I end up writing
or
If I'm not specifying a more narrow type why does mypy require me to annotate the variables in a way that gives it no additional information. If I type
[]
then# type: list
is just additional noise.The text was updated successfully, but these errors were encountered: