mirror of
https://github.com/github/codeql.git
synced 2026-04-26 09:15:12 +02:00
Python: Extend test cases for "unused global var" query
Adds two test cases having to do with type annotations. The first one demonstrates that type annotations (even if they are never executed by the Python interpreter) count as uses for the purposes of the unused variable query. The second one demonstrates that this is _not_ the case if all such uses are inside strings (i.e. forward declarations), as we do not currently inspect the content of these strings.
This commit is contained in:
@@ -4,3 +4,6 @@
|
||||
| variables_test.py:86:3:86:3 | b | The global variable 'b' is not used. |
|
||||
| variables_test.py:86:5:86:5 | c | The global variable 'c' is not used. |
|
||||
| variables_test.py:100:1:100:8 | glob_var | The global variable 'glob_var' is not used. |
|
||||
| variables_test.py:147:5:147:26 | ForwardParamAnnotation | The global variable 'ForwardParamAnnotation' is not used. |
|
||||
| variables_test.py:148:5:148:27 | ForwardReturnAnnotation | The global variable 'ForwardReturnAnnotation' is not used. |
|
||||
| variables_test.py:149:5:149:31 | ForwardAssignmentAnnotation | The global variable 'ForwardAssignmentAnnotation' is not used. |
|
||||
|
||||
@@ -137,3 +137,21 @@ def test_dict_unpacking(queryset, field_name, value):
|
||||
for tag in value.split(','):
|
||||
queryset = queryset.filter(**{field_name + '__name': tag})
|
||||
return queryset
|
||||
|
||||
from typing import TYPE_CHECKING
|
||||
|
||||
if TYPE_CHECKING:
|
||||
ParamAnnotation = int
|
||||
ReturnAnnotation = int
|
||||
AssignmentAnnotation = int
|
||||
ForwardParamAnnotation = int
|
||||
ForwardReturnAnnotation = int
|
||||
ForwardAssignmentAnnotation = int
|
||||
|
||||
def test_direct_annotation(x: ParamAnnotation) -> ReturnAnnotation:
|
||||
if x:
|
||||
y : AssignmentAnnotation = 1
|
||||
|
||||
def test_forward_annotation(x: "ForwardParamAnnotation") -> "ForwardReturnAnnotation":
|
||||
if x:
|
||||
y : "ForwardAssignmentAnnotation" = 1
|
||||
|
||||
Reference in New Issue
Block a user