Skip to content

Commit 7beafc9

Browse files
authored
Merge pull request github#15755 from RasmusWL/it-fix
Python: Fix module level flow for iterable unpacking
2 parents 0e93f5a + 8079788 commit 7beafc9

File tree

3 files changed

+14
-3
lines changed

3 files changed

+14
-3
lines changed
Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,4 @@
1+
---
2+
category: minorAnalysis
3+
---
4+
* Fixed flow for iterable unpacking (`a,b = my_tuple`) when it occurs on top-level (module) scope.

python/ql/lib/semmle/python/dataflow/new/internal/DataFlowPublic.qll

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -467,7 +467,7 @@ class IterableSequenceNode extends Node, TIterableSequenceNode {
467467

468468
override string toString() { result = "IterableSequence" }
469469

470-
override DataFlowCallable getEnclosingCallable() { result = consumer.getEnclosingCallable() }
470+
override Scope getScope() { result = consumer.getScope() }
471471

472472
override Location getLocation() { result = consumer.getLocation() }
473473
}
@@ -484,7 +484,7 @@ class IterableElementNode extends Node, TIterableElementNode {
484484

485485
override string toString() { result = "IterableElement" }
486486

487-
override DataFlowCallable getEnclosingCallable() { result = consumer.getEnclosingCallable() }
487+
override Scope getScope() { result = consumer.getScope() }
488488

489489
override Location getLocation() { result = consumer.getLocation() }
490490
}
@@ -499,7 +499,7 @@ class StarPatternElementNode extends Node, TStarPatternElementNode {
499499

500500
override string toString() { result = "StarPatternElement" }
501501

502-
override DataFlowCallable getEnclosingCallable() { result = consumer.getEnclosingCallable() }
502+
override Scope getScope() { result = consumer.getScope() }
503503

504504
override Location getLocation() { result = consumer.getLocation() }
505505
}
Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,7 @@
1+
# this test has code on module level, which works in slightly different ways than when
2+
# inside a function
3+
4+
t = (SOURCE, NONSOURCE)
5+
a, b = t
6+
SINK(a) #$ flow="SOURCE, l:-2 -> a"
7+
SINK_F(b)

0 commit comments

Comments
 (0)