Skip to content

Commit 39dc697

Browse files
committed
Python: DefinitionNode for with
1 parent e011b4b commit 39dc697

File tree

1 file changed

+6
-0
lines changed

1 file changed

+6
-0
lines changed

python/ql/lib/semmle/python/Flow.qll

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -672,6 +672,8 @@ class DefinitionNode extends ControlFlowNode {
672672
exists(For for | for.getTarget().getAFlowNode() = this)
673673
or
674674
exists(Parameter param | this = param.asName().getAFlowNode() and exists(param.getDefault()))
675+
or
676+
exists(With with | this = with.getOptionalVars().getAFlowNode())
675677
}
676678

677679
/** flow node corresponding to the value assigned for the definition corresponding to this flow node */
@@ -840,7 +842,11 @@ private AstNode assigned_value(Expr lhs) {
840842
/* for lhs in seq: => `result` is the `for` node, representing the `iter(next(seq))` operation. */
841843
result.(For).getTarget() = lhs
842844
or
845+
// def f(a = 42): => `result` is 42
843846
exists(Parameter param | lhs = param.asName() and result = param.getDefault())
847+
or
848+
// with f(42) as x: => `result` is `f(42)`
849+
exists(With with | lhs = with.getOptionalVars() and result = with.getContextExpr())
844850
}
845851

846852
predicate nested_sequence_assign(

0 commit comments

Comments
 (0)