Skip to content

None-ness falsely assumed in loop #11430

@Akuli

Description

@Akuli

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

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

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions