Skip to content

reportUnusedVariable false positive #10512

@ar0ck

Description

@ar0ck

I've narrowed a typing failure down to the following snippet:

# pyright: reportUnusedVariable=true

def f(a: int):
    b = {}
    c = a
    used = 1
    for _ in range(1):
        if a:
            pass
        if 0:
            b[c].append(0)
        c = used if 1 else 0

f(0)

With pyright==1.1.401, this yields: error: Variable "used" is not accessed.

This seems incorrect - if I remove used = 1, then this crashes with NameError: name 'used' is not defined.

Metadata

Metadata

Assignees

No one assigned

    Labels

    addressed in next versionIssue is fixed and will appear in next published versionbugSomething isn't working

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions