Skip to content

Python: False Positive on Global Type Variable #18910

@cariad-robert-abel

Description

@cariad-robert-abel

A globally defined type variable, usually a short-hand, is reported as being an unused global variable py/unused-global-variable, when it reality it's not, because it's used in a string type annotation.

Our code is closed source, so unfortunately a made up example will have illustrate the false positive:

from typing import TYPE_CHECKING

if TYPE_CHECKING:
    JiraIssue = dict[str, str]

def titlecase_jira_issues(issues: list['JiraIssue']):
    
    for issue in issues:
        issue['title'] = issue['title'].title()

In the snippet above, JiraIssue is reported as unused. We're using the codeql-bundle-v2.20.5/codeql-bundle-linux64.tar.zst.

The closest related issue I could find deals with a similar case involving unused imports, see #2042.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions