Skip to content

Commit 69640f3

Browse files
committed
Python: refactor awaited
1 parent ea74317 commit 69640f3

File tree

2 files changed

+20
-7
lines changed

2 files changed

+20
-7
lines changed

python/ql/lib/semmle/python/ApiGraphs.qll

Lines changed: 3 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -570,8 +570,7 @@ module API {
570570
* API graph node for the prefix `foo`), in accordance with the usual semantics of Python.
571571
*/
572572

573-
private import semmle.python.internal.Awaited
574-
573+
// private import semmle.python.internal.Awaited
575574
cached
576575
newtype TApiNode =
577576
/** The root of the API graph. */
@@ -762,11 +761,8 @@ module API {
762761
)
763762
or
764763
// awaiting
765-
exists(DataFlow::Node awaitedValue |
766-
lbl = Label::await() and
767-
ref = awaited(awaitedValue) and
768-
pred.flowsTo(awaitedValue)
769-
)
764+
lbl = Label::await() and
765+
ref = pred.getAnAwaited()
770766
)
771767
or
772768
exists(DataFlow::Node def, PY::CallableExpr fn |

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

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@ private import python
1010
import DataFlowPublic
1111
private import DataFlowPrivate
1212
private import semmle.python.internal.CachedStages
13+
private import semmle.python.internal.Awaited
1314

1415
/**
1516
* A data flow node that is a source of local flow. This includes things like
@@ -95,6 +96,11 @@ class LocalSourceNode extends Node {
9596
*/
9697
CallCfgNode getACall() { Cached::call(this, result) }
9798

99+
/**
100+
* Gets an awaited value from this node.
101+
*/
102+
Node getAnAwaited() { Cached::await(this, result) }
103+
98104
/**
99105
* Gets a call to the method `methodName` on this node.
100106
*
@@ -225,4 +231,15 @@ private module Cached {
225231
n = call.getFunction()
226232
)
227233
}
234+
235+
/**
236+
* Holds if `node` flows to the awaited value of `awaited`.
237+
*/
238+
cached
239+
predicate await(LocalSourceNode node, Node awaited) {
240+
exists(Node awaitedValue |
241+
node.flowsTo(awaitedValue) and
242+
awaited = awaited(awaitedValue)
243+
)
244+
}
228245
}

0 commit comments

Comments
 (0)