Skip to content

Commit 66426bf

Browse files
committed
Python: Add tests for iterable unpacking
in for-iterations and comprehensions.
1 parent 175e43d commit 66426bf

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

  • python/ql/test/experimental/dataflow/coverage

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

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,12 @@ def test_nested_comprehension_paren():
200200
SINK(x[0])
201201

202202

203+
# Iterable unpacking in comprehensions
204+
def test_unpacking_comprehension():
205+
x = [a for (a, b) in [(SOURCE, NONSOURCE)]]
206+
SINK(x[0]) # Flow missing
207+
208+
203209
# 6.2.8. Generator expressions
204210
def test_generator():
205211
x = (SOURCE for y in [NONSOURCE])
@@ -620,6 +626,23 @@ def test_iterated_unpacking_assignment_conversion():
620626
SINK_F(b[0])
621627

622628

629+
@expects(4)
630+
def test_iterable_unpacking_in_for():
631+
tl = [(SOURCE, NONSOURCE), (SOURCE, NONSOURCE)]
632+
for x,y in tl:
633+
SINK(x) # Flow missing
634+
SINK_F(y)
635+
636+
637+
@expects(6)
638+
def test_iterable_star_unpacking_in_for():
639+
tl = [(SOURCE, NONSOURCE), (SOURCE, NONSOURCE)]
640+
for *x,y in tl:
641+
SINK_F(x)
642+
SINK(x[0]) # Flow missing
643+
SINK_F(y)
644+
645+
623646
def test_deep_callgraph():
624647
# port of python/ql/test/library-tests/taint/general/deep.py
625648

0 commit comments

Comments
 (0)