-
-
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
False negative involving null checks on optional types #5423
Comments
Hm, indeed, the conditional binder still doesn't catch all the corner cases. But actually by preference would be to just show errors in unreachable code in the strict mode. |
This bug is actually pretty bad, I think. It comes up not infrequently and has a pretty bad knock-on effect on mypyc, where it causes bizarre type errors of the form |
@msullivan |
This might be easy to fix without a major refactoring. Maybe we only need to modify how |
Hm, there are cases where this breaks mypyc without
|
Currently when we encounter #5423 (when someting is incorrectly inferred as None), we generate code that casts a variable to None incorrectly since we are confused about the real type. Now produce an error message saying to add an annotation when we detect it. Fix up the places in mypy this caused errors.
Currently when we encounter #5423 (when someting is incorrectly inferred as None), we generate code that casts a variable to None incorrectly since we are confused about the real type. Now produce an error message saying to add an annotation when we detect it. Fix up the places in mypy this caused errors.
Currently when we encounter #5423 (when someting is incorrectly inferred as None), we generate code that casts a variable to None incorrectly since we are confused about the real type. Now produce an error message saying to add an annotation when we detect it. Fix up the places in mypy this caused errors.
If a default includes a reference to a variable, expand that reference. See test_environs.test_default_expands. Note: type for subs_default is required because of a bug in mypy: python/mypy#5423
* Apply variable expansion to default values If a default includes a reference to a variable, expand that reference. See test_environs.test_default_expands. Note: type for subs_default is required because of a bug in mypy: python/mypy#5423 * Update CHANGELOG Co-authored-by: Richard Cohn <[email protected]> Co-authored-by: Steven Loria <[email protected]>
in case anyone comes here for help: (lesson for me here is; always try to annotate more, it'll not only help me but also mypy) |
Here is a minimal program demonstrating the problem:
Expected behavior:
error: Value of type "int" is not indexable
Actual behavior:
mypy accepts the program as valid, when run with the --strict flag
This issue seems to be a problem with how mypy handles reassignment to None type variables, and static evaluation of conditionals. After line 1,
foo
has the type None according to mypy. Thus, mypy determines that the condition on line 3 will never hold, and thus doesn't do type checking for the body of the if statement. On line 5, foo's type changes toOptional[int]
. This, however, will only be reflected in code that follows line 5.The text was updated successfully, but these errors were encountered: