Skip to content

Commit 4a98ed9

Browse files
committed
Python: Fix consistency for bound-methods used in list-comp
1 parent 67b1414 commit 4a98ed9

File tree

1 file changed

+20
-4
lines changed

1 file changed

+20
-4
lines changed

python/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 20 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -66,10 +66,26 @@ private module Input implements InputSig<PythonDataFlow> {
6666
// Example: In `bm = self.foo; bm(); bm()` both bm() calls use the same `self` as
6767
// the (pos self) argument
6868
exists(AttrRead attr, DataFlowCall other | other != call |
69-
any(CfgNode n | n.asCfgNode() = call.getNode().(CallNode).getFunction()).getALocalSource() =
70-
attr and
71-
any(CfgNode n | n.asCfgNode() = other.getNode().(CallNode).getFunction()).getALocalSource() =
72-
attr and
69+
// for simple cases we can track the function back to the attr read but when the
70+
// call appears in the body of a list-comprehension, we can't do that, and simply
71+
// allow it instead.
72+
(
73+
call.getScope() = attr.getScope() and
74+
any(CfgNode n | n.asCfgNode() = call.getNode().(CallNode).getFunction()).getALocalSource() =
75+
attr
76+
or
77+
not exists(call.getScope().(Function).getDefinition()) and
78+
call.getScope().getScope+() = attr.getScope()
79+
) and
80+
(
81+
other.getScope() = attr.getScope() and
82+
any(CfgNode n | n.asCfgNode() = other.getNode().(CallNode).getFunction()).getALocalSource() =
83+
attr
84+
or
85+
not exists(other.getScope().(Function).getDefinition()) and
86+
other.getScope().getScope+() = attr.getScope()
87+
) and
88+
arg = attr.getObject() and
7389
arg = call.getArgument(any(ArgumentPosition p | p.isSelf())) and
7490
arg = other.getArgument(any(ArgumentPosition p | p.isSelf()))
7591
)

0 commit comments

Comments
 (0)