-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Expand file tree
/
Copy pathvariables_test.py
More file actions
157 lines (95 loc) · 2.19 KB
/
variables_test.py
File metadata and controls
157 lines (95 loc) · 2.19 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
__all__ = [ 'is_used_var1' ]
__author__ = "Mark"
__hidden_marker = False
#Unused parameter, local and global
def u1(x):
return 0
def u2():
x = 1
return 1
#These parameters are OK due to (potential overriding)
class C(object):
@abstractmethod
def ok2(self, p):
pass
def ok3(self, arg):
pass
class D(C):
def ok3(self, arg):
pass
#Unused module variable
not_used_var1 = 17
not_used_var2 = 18
is_used_var1 = 19
is_used_var2 = 20
def func():
return is_used_var2
#Redundant global declaration
global g_x
g_x = 0
#Use global
def uses_global(arg):
global g_x
g_x = arg
use(g_x)
#Unused but with acceptable names
unused_var3 = g_x
#Use at least one element of the tuple
_a, _b, c = t
use(c)
def f(t):
_a, _b, c = t
use(c)
# Entirely unused tuple
a,b,c = t
def f(t):
a,b,c = t
use(t)
def second_def_undefined():
var = 0
use(var)
var = 1 # unused.
#And gloablly
glob_var = 0
use(glob_var)
glob_var = 1 # unused
#OK if marked as unused:
def ok_unused(unused_1):
unused_2 = 1
return 0
#Decorators count as a use:
@compound.decorator()
def _unused_but_decorated():
pass
def decorated_inner_function():
@flasklike.routing("/route")
def end_point():
pass
@complex.decorator("x")
class C(object):
pass
return 0
#FP observed
def test_dict_unpacking(queryset, field_name, value):
#True positive
for tag in value.split(','):
queryset = queryset.filter(**{field_name + '__name': tag1})
return queryset
#False positive
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