Skip to content

Commit a50b193

Browse files
committed
Python: Model data-flow for x or y and x and y
1 parent 15476c2 commit a50b193

File tree

3 files changed

+8
-2
lines changed

3 files changed

+8
-2
lines changed
Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
lgtm,codescanning
2+
* Added data-flow from `x` in both `x or y` and `x and y`, as described in the
3+
[Python Language Reference](https://docs.python.org/3/reference/expressions.html#boolean-operations).

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

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -200,6 +200,9 @@ module EssaFlow {
200200
// If expressions
201201
nodeFrom.asCfgNode() = nodeTo.asCfgNode().(IfExprNode).getAnOperand()
202202
or
203+
// boolean inline expressions such as `x or y` or `x and y`
204+
nodeFrom.asCfgNode() = nodeTo.asCfgNode().(BoolExprNode).getAnOperand()
205+
or
203206
// Flow inside an unpacking assignment
204207
iterableUnpackingFlowStep(nodeFrom, nodeTo)
205208
or

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -426,12 +426,12 @@ def test_call_extra_keyword_flow():
426426

427427
def test_or(x = False):
428428
# if we don't know the value of the lhs, we should always add flow
429-
SINK(x or SOURCE) #$ MISSING: flow="SOURCE -> BoolExp"
429+
SINK(x or SOURCE) #$ flow="SOURCE -> BoolExpr"
430430

431431

432432
def test_and(x = True):
433433
# if we don't know the value of the lhs, we should always add flow
434-
SINK(x and SOURCE) #$ MISSING: flow="SOURCE -> BoolExp"
434+
SINK(x and SOURCE) #$ flow="SOURCE -> BoolExpr"
435435

436436

437437
# 6.12. Assignment expressions

0 commit comments

Comments
 (0)