You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
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:
Fixes the false positive reported in
#18910
Adds a new `Annotation` class (subclass of `Expr`) which encompasses all
possible kinds of annotations in Python.
Using this, we look for string literals which are part of an annotation,
and which have the same content as the name of a (potentially) unused
global variable, and in that case we do not produce an alert.
In future, we may want to support inspecting such string literals more
deeply (e.g. to support stuff like "list[unused_var]"), but I think for
now this level of support is sufficient.
Thanks for reporting this! I have run this past the relevant engineering team and they confirm that support for string type annotations in Python is currently limited here. We will keep track of this issue internally. Although fixing false positives is not a current product priority and I cannot say how long it may take until this is fixed, the engineering team is working on a potential fix for this.
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:
In the snippet above,
JiraIssue
is reported as unused. We're using thecodeql-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.
The text was updated successfully, but these errors were encountered: