Skip to content

UnboundLocalError in nested function is not detected by mypy #13988

Closed as not planned
@ltworf

Description

@ltworf

Bug Report

Mypy does not detect invalid usage within nested functions. This might be a duplicate of #8746 but I thought it's a different issue.

To Reproduce

def a() -> None:
    val = 0
    def b() -> None:
        val += 1
    b()
a()

Expected Behavior

I'd like mypy to mark val += 1 as an error, as the runtime does

Actual Behavior

Code is considered correct.

Your Environment

  • Mypy version used: 0.982
  • Mypy command-line flags: None
  • Python version used: 3.10.8

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