Skip to content

Commit cdf4dd1

Browse files
committed
Python: Fix module level flow for iterable unpacking
(and for * patterns in match) Since `PhaseDependentFlow` uses the following predicate, that relies on .getScope() to be present for there to be any importTimeFlow (flow at toplevel scope), it's important that data-flow nodes implement `.getScope`. ``` private predicate isTopLevel(Node node) { node.getScope() instanceof Module } ``` By implementing getScope, we can now rely on default implementation of `getEnclosingCallable` in DataFlow::Node: ``` /** Gets the enclosing callable of this node. */ DataFlowCallable getEnclosingCallable() { result = getCallableScope(this.getScope()) } ```
1 parent e4699e0 commit cdf4dd1

File tree

2 files changed

+4
-4
lines changed

2 files changed

+4
-4
lines changed

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
}

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,5 +3,5 @@
33

44
t = (SOURCE, NONSOURCE)
55
a, b = t
6-
SINK(a) #$ MISSING: flow="SOURCE, l:-2 -> a"
6+
SINK(a) #$ flow="SOURCE, l:-2 -> a"
77
SINK_F(b)

0 commit comments

Comments
 (0)