Skip to content

False positive with closures where variable is not reassigned (or del'd) #559

@hauntsaninja

Description

@hauntsaninja
def foo(x: str | None):
    if x is None:
        x = "asdf"

    def inner():
        return x + "foo"

pyright looks for reassignments following the closure definition in the flow graph. mypy does something similar (but its implementation is a little sketchier). This heuristic seems to work fairly well in practice. Was a very common cause of user confusion and duplicate reports before mypy added support for this.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions