-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Ask for an explicit annotation if the inferred type is None #3741
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
Requiring an explicit annotation would be consistent with how we treat |
I bisected, and it's indeed a regression caused by PR #3024 (Make strict Optional type system changes standard). Ideally we'd have this fixed in the 0.521 release. |
CC @ddfisher |
This wasn't a regression exactly, but rather a purposeful decision about how None types should work in strict Optional that we made in the early days. This change in how NoneType was treated was incorporated into the main part of mypy along with the other main typechecking changes from strict Optional. Also, intending for a variable to have type None based only on initial assignment isn't incredibly uncommon. It happens 21 times in the test suite and 88 times across the Dropbox internal codebase (but it doesn't happen at all in mypy). Have we actually had any new users confused by this? |
If we decide we want to implement this and want it out by release, feel free to merge #3755. Note that this is likely to break at least some user code. |
@vlasovskikh was confused by the error on the code @ilevkivskyi posted in the original comment. See https://gitter.im/python/typing?at=596faa652723db8d5e28fe6e and following comments. |
We've been incorporating mypy into our production workflow and we've had people hit this and be confused. I was able to walk them through it, but I also have dived fairly deep into the docs and have been playing with mypy longer than most people here. |
#3755 is closed as wontfix so closing this as well. |
Currently mypy behaves like this
This may be non-intuitive for new users. Instead, it is proposed to either:
None
, like we would do forlst = []
.None
types, like we would do if both assignments were within the same function.cc @vlasovskikh
The text was updated successfully, but these errors were encountered: