-
-
Notifications
You must be signed in to change notification settings - Fork 2.8k
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
Failure to detect non-None Optional type in conditional expression #6755
Comments
I agree this behavior is inconsistent. Mypy already allows (on purpose) some code that may be technically unsafe (e.g. Btw, the same same happens in normal if statement, not only in a ternary expression: if names_to_numbers['foo']: # error also disappears if I add 'is not None'
squares[names_to_numbers['foo']] # same error here |
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
This comment has been minimized.
@JelleZijlstra OK, migrated there! Thanks! |
This is no longer reproducible on mypy 0.930+ |
Are you reporting a bug, or opening a feature request?
Bug
Please insert below the code you are checking with mypy, or a mock-up repro if the source is private. We would appreciate if you try to simplify your case to a minimal repro.
This error is only thrown for conditional expressions of the form
if container[index] else None
. Changing it to any of the following works as expected:What is the behavior/output you expect?
No errors reported.
What are the versions of mypy and Python you are using?
mypy 0.701, reproducible on at least Python 2.7 and 3.7.
Do you see the same issue after installing mypy from Git master?
Yes
The text was updated successfully, but these errors were encountered: