Skip to content

Mypy doesn't check for unbound variables #16609

@1PaCHeK1

Description

@1PaCHeK1

Bug Report

Ignore Unbound variable

To Reproduce

Gist URL: https://gist.github.com/mypy-play/d2f10eb93875541fd255cd23f4c4a790
Playground URL: https://mypy-play.net/?mypy=latest&python=3.11&gist=d2f10eb93875541fd255cd23f4c4a790

def func(flag: bool) -> str:
    if flag:
        name = "Name"
    return name


func(False)

Expected Behavior
error: unbound name variable

Actual Behavior
Type checking succeeds

  • Mypy version used: 1.7.1
  • Mypy command-line flags: None
  • Mypy configuration options from mypy.ini (and other config files): Empty, this is reproducable on mypy playground
  • Python version used: 3.11.3

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugmypy got something wrong
    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions