**Bug Report** After `foo = None`, mypy thinks that `foo` will always be `None`, even if a loop can jump between the assignment and the use of `foo`. **To Reproduce** ```python def main() -> None: gonna_select = None while True: if gonna_select is not None: print(1 + "lol") gonna_select = "lol" ``` **Expected Behavior** error from `1 + "lol"` **Actual Behavior** no error **Your Environment** - Mypy version used: 0.910 - Mypy command-line flags: none - Mypy configuration options from `mypy.ini` (and other config files): none - Python version used: 3.7
Activity
[-]"is not None" falsely not analyzed[/-][+]None-ness falsely assumed[/+][-]None-ness falsely assumed[/-][+]None-ness falsely assumed in loop[/+]intgr commentedon Nov 8, 2021
I think the real error should be here. Since mypy infers
gonna_selectas typeNone, why does it allow assigning a string to it?A5rocks commentedon Jan 22, 2025
Fixed by #18433