Skip to content

Commit dc36609

Browse files
committed
Python: Add data-flow tests
Alas, all these demonstrate is that we already don't fully support the desugared `yield from` form.
1 parent 6c675fc commit dc36609

File tree

1 file changed

+26
-0
lines changed
  • python/ql/test/library-tests/dataflow/coverage

1 file changed

+26
-0
lines changed

python/ql/test/library-tests/dataflow/coverage/test.py

Lines changed: 26 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -257,6 +257,32 @@ def test_yield_from():
257257
SINK(next(g)) # $ MISSING:flow="SOURCE, l:-1 -> next()"
258258

259259

260+
# PEP 798: Unpacking in comprehensions.
261+
# These desugar to `yield from`, so flow depends on yield-from support (see above).
262+
def test_star_list_comp():
263+
l = [[SOURCE]]
264+
flat = [*x for x in l]
265+
SINK(flat[0]) # $ MISSING:flow="SOURCE, l:-2 -> flat[0]"
266+
267+
268+
def test_star_set_comp():
269+
l = [[SOURCE]]
270+
flat = {*x for x in l}
271+
SINK(flat.pop()) # $ MISSING:flow="SOURCE, l:-2 -> flat.pop()"
272+
273+
274+
def test_star_genexp():
275+
l = [[SOURCE]]
276+
g = (*x for x in l)
277+
SINK(next(g)) # $ MISSING:flow="SOURCE, l:-2 -> next()"
278+
279+
280+
def test_star_dictcomp():
281+
l = [{"key": SOURCE}]
282+
merged = {**d for d in l}
283+
SINK(merged["key"]) # $ MISSING:flow="SOURCE, l:-2 -> merged[..]"
284+
285+
260286
# a statement rather than an expression, but related to generators
261287
def test_for():
262288
for x in gen(SOURCE):

0 commit comments

Comments
 (0)