Skip to content

"unused" false positive on declared variable with type annotation and no assignment #3322

@DetachHead

Description

@DetachHead

Summary

Playground

main.py

def fn(value: bool):
    a: int  # hint: `a` is unused
    if value:
        a = 1
    else:
        a = 2

    return a

this is a common pattern if you want to explicitly declare the type before assignment if it's assigned in multiple possible spots. this declaration is not an assignment so it should not be considered unused

Version

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't workingserverRelated to the LSP server

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions