Skip to content

Commit 133e18e

Browse files
committed
Python: Annotate missing flow
1 parent 1467d6b commit 133e18e

File tree

1 file changed

+41
-39
lines changed
  • python/ql/test/experimental/dataflow/coverage

1 file changed

+41
-39
lines changed

python/ql/test/experimental/dataflow/coverage/test.py

Lines changed: 41 additions & 39 deletions
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@ def SINK(x):
1616
def test_tuple_with_local_flow():
1717
x = (3, SOURCE)
1818
y = x[1]
19-
SINK(y)
19+
SINK(y) # Flow missing
2020

2121
# 6.2.1. Identifiers (Names)
2222
def test_names():
@@ -42,81 +42,81 @@ def test_floatnumber_literal():
4242

4343
def test_imagnumber_literal():
4444
x = 42j
45-
SINK(x)
45+
SINK(x) # Flow missing
4646

4747
# 6.2.3. Parenthesized forms
4848
def test_parenthesized_form():
4949
x = (SOURCE)
50-
SINK(x)
50+
SINK(x) # Flow missing
5151

5252
# 6.2.5. List displays
5353
def test_list_display():
5454
x = [SOURCE]
55-
SINK(x[0])
55+
SINK(x[0]) # Flow missing
5656

5757
def test_list_comprehension():
5858
x = [SOURCE for y in [3]]
59-
SINK(x[0])
59+
SINK(x[0]) # Flow missing
6060

6161
def test_nested_list_display():
6262
x = [* [SOURCE]]
63-
SINK(x[0])
63+
SINK(x[0]) # Flow missing
6464

6565
# 6.2.6. Set displays
6666
def test_set_display():
6767
x = {SOURCE}
68-
SINK(x.pop())
68+
SINK(x.pop()) # Flow missing
6969

7070
def test_set_comprehension():
7171
x = {SOURCE for y in [3]}
72-
SINK(x.pop())
72+
SINK(x.pop()) # Flow missing
7373

7474
def test_nested_set_display():
7575
x = {* {SOURCE}}
76-
SINK(x.pop())
76+
SINK(x.pop()) # Flow missing
7777

7878
# 6.2.7. Dictionary displays
7979
def test_dict_display():
8080
x = {"s": SOURCE}
81-
SINK(x["s"])
81+
SINK(x["s"]) # Flow missing
8282

8383
def test_dict_comprehension():
8484
x = {y: SOURCE for y in ["s"]}
85-
SINK(x["s"])
85+
SINK(x["s"]) # Flow missing
8686

8787
def test_nested_dict_display():
8888
x = {** {"s": SOURCE}}
89-
SINK(x["s"])
89+
SINK(x["s"]) # Flow missing
9090

9191
# 6.2.8. Generator expressions
9292
def test_generator():
9393
x = (SOURCE for y in [3])
94-
SINK([*x][0])
94+
SINK([*x][0]) # Flow missing
9595

9696
# 6.2.9. Yield expressions
9797
def gen(x):
9898
yield x
9999

100100
def test_yield():
101101
g = gen(SOURCE)
102-
SINK(next(g))
102+
SINK(next(g)) # Flow missing
103103

104104
def gen_from(x):
105105
yield from gen(x)
106106

107107
def test_yield_from():
108108
g = gen_from(SOURCE)
109-
SINK(next(g))
109+
SINK(next(g)) # Flow missing
110110

111111
# a statement rather than an expression, but related to generators
112112
def test_for():
113113
for x in gen(SOURCE):
114-
SINK(x)
114+
SINK(x) # Flow missing
115115

116116
# 6.2.9.1. Generator-iterator methods
117117
def test___next__():
118118
g = gen(SOURCE)
119-
SINK(g.__next__())
119+
SINK(g.__next__()) # Flow missing
120120

121121
def gen2(x):
122122
m = yield x # argument of `send` has to flow to value of `yield x` (and so to `m`)
@@ -125,7 +125,7 @@ def gen2(x):
125125
def test_send():
126126
g = gen2(3)
127127
n = next(g)
128-
SINK(g.send(SOURCE))
128+
SINK(g.send(SOURCE)) # Flow missing
129129

130130
def gen_ex(x):
131131
try:
@@ -136,7 +136,7 @@ def gen_ex(x):
136136
def test_throw():
137137
g = gen_ex(SOURCE)
138138
n = next(g)
139-
SINK(g.throw(TypeError))
139+
SINK(g.throw(TypeError)) # Flow missing
140140

141141
# no `test_close` as `close` involves no data flow
142142

@@ -153,7 +153,7 @@ def runa(a):
153153

154154
async def atest___anext__():
155155
g = agen(SOURCE)
156-
SINK(await g.__anext__())
156+
SINK(await g.__anext__()) # Flow missing
157157

158158
def test___anext__():
159159
runa(atest___anext__())
@@ -165,7 +165,7 @@ async def agen2(x):
165165
async def atest_asend():
166166
g = agen2(3)
167167
n = await g.__anext__()
168-
SINK(await g.asend(SOURCE))
168+
SINK(await g.asend(SOURCE)) # Flow missing
169169

170170
def test_asend():
171171
runa(atest_asend())
@@ -179,7 +179,7 @@ async def agen_ex(x):
179179
async def atest_athrow():
180180
g = agen_ex(SOURCE)
181181
n = await g.__anext__()
182-
SINK(await g.athrow(TypeError))
182+
SINK(await g.athrow(TypeError)) # Flow missing
183183

184184
def test_athrow():
185185
runa(atest_athrow())
@@ -189,23 +189,23 @@ class C:
189189
a = SOURCE
190190

191191
def test_attribute_reference():
192-
SINK(C.a)
192+
SINK(C.a) # Flow missing
193193

194194
# overriding __getattr__ should be tested by the class coverage tests
195195

196196
# 6.3.2. Subscriptions
197197
# This does not constitute dataflow (but could be taint flow)
198198
def example_subscription_string():
199-
SINK("source"[0])
199+
SINK("source"[0]) # Flow not expected
200200

201201
def test_subscription_tuple():
202-
SINK((SOURCE,)[0])
202+
SINK((SOURCE,)[0]) # Flow missing
203203

204204
def test_subscription_list():
205-
SINK([SOURCE][0])
205+
SINK([SOURCE][0]) # Flow missing
206206

207207
def test_subscription_mapping():
208-
SINK({"s":SOURCE}["s"])
208+
SINK({"s":SOURCE}["s"]) # Flow missing
209209

210210
# overriding __getitem__ should be tested by the class coverage tests
211211

@@ -214,7 +214,7 @@ def test_subscription_mapping():
214214

215215
def test_slicing():
216216
s = l[0:1:1]
217-
SINK(s[0])
217+
SINK(s[0]) # Flow missing
218218

219219
# The grammar seems to allow `l[0:1:1, 0:1]`, but the interpreter does not like it
220220

@@ -226,53 +226,55 @@ def test_call_positional():
226226
SINK(f(3, SOURCE))
227227

228228
def test_call_keyword():
229-
SINK(f(3, b=SOURCE))
229+
SINK(f(3, b=SOURCE)) # Flow missing
230230

231231
def test_call_unpack_iterable():
232-
SINK(f(3, *[SOURCE]))
232+
SINK(f(3, *[SOURCE])) # Flow missing
233233

234234
def test_call_unpack_mapping():
235-
SINK(f(3, **{"b": SOURCE}))
235+
SINK(f(3, **{"b": SOURCE})) # Flow missing
236236

237237
def f_extra_pos(a, *b):
238238
return b[0]
239239

240240
def test_call_extra_pos():
241-
SINK(f_extra_pos(3, SOURCE))
241+
SINK(f_extra_pos(3, SOURCE)) # Flow missing
242242

243243
def f_extra_keyword(a, **b):
244244
return b["b"]
245245

246246
def test_call_extra_keyword():
247-
SINK(f_extra_keyword(3, b=SOURCE))
247+
SINK(f_extra_keyword(3, b=SOURCE)) # Flow missing
248248

249249
# return the name of the first extra keyword argument
250250
def f_extra_keyword_flow(**a):
251251
return [*a][0]
252252

253253
# call the function with our source as the name of the keyword arguemnt
254254
def test_call_extra_keyword_flow():
255-
SINK(f_extra_keyword_flow(**{SOURCE: None}))
255+
SINK(f_extra_keyword_flow(**{SOURCE: None})) # Flow missing
256256

257257
# 6.12. Assignment expressions
258258
def test_assignment_expression():
259259
x = 3
260-
SINK(x := SOURCE)
260+
SINK(x := SOURCE) # Flow missing
261261

262262
# 6.13. Conditional expressions
263263
def test_conditional_true():
264-
SINK(SOURCE if True else 3)
264+
SINK(SOURCE if True else 3) # Flow missing
265265

266266
def test_conditional_false():
267-
SINK(3 if False else SOURCE)
267+
SINK(3 if False else SOURCE) # Flow missing
268268

269+
# Condition is evaluated first, so x is SOURCE once chosen
269270
def test_conditional_evaluation_true():
270271
x = 3
271-
SINK(x if (SOURCE == (x := SOURCE)) else 3) # Condition is evaluated first, so x is SOURCE once chosen
272+
SINK(x if (SOURCE == (x := SOURCE)) else 3) # Flow missing
272273

274+
# Condition is evaluated first, so x is SOURCE once chosen
273275
def test_conditional_evaluation_false():
274276
x = 3
275-
SINK(3 if (3 == (x := SOURCE)) else x) # Condition is evaluated first, so x is SOURCE once chosen
277+
SINK(3 if (3 == (x := SOURCE)) else x) # Flow missing
276278

277279
# 6.14. Lambdas
278280
def test_lambda():

0 commit comments

Comments
 (0)