Skip to content

Commit f80a091

Browse files
committed
Python: Don't report get/setdefault as unresolved calls for dict tests
1 parent e0e978b commit f80a091

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

python/ql/test/experimental/dataflow/TestUtil/UnresolvedCalls.qll

Lines changed: 9 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,14 +9,17 @@ class UnresolvedCallExpectations extends InlineExpectationsTest {
99

1010
override string getARelevantTag() { result = "unresolved_call" }
1111

12+
predicate unresolvedCall(CallNode call) {
13+
not exists(DataFlowPrivate::DataFlowCall dfc |
14+
exists(dfc.getCallable()) and dfc.getNode() = call
15+
) and
16+
not DataFlowPrivate::resolveClassCall(call, _) and
17+
not call = API::builtin(_).getACall().asCfgNode()
18+
}
19+
1220
override predicate hasActualResult(Location location, string element, string tag, string value) {
1321
exists(location.getFile().getRelativePath()) and
14-
exists(CallNode call |
15-
not exists(DataFlowPrivate::DataFlowCall dfc |
16-
exists(dfc.getCallable()) and dfc.getNode() = call
17-
) and
18-
not DataFlowPrivate::resolveClassCall(call, _) and
19-
not call = API::builtin(_).getACall().asCfgNode() and
22+
exists(CallNode call | this.unresolvedCall(call) |
2023
location = call.getLocation() and
2124
tag = "unresolved_call" and
2225
value = prettyExpr(call.getNode()) and
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,2 +1,12 @@
11
import python
22
import experimental.dataflow.TestUtil.UnresolvedCalls
3+
private import semmle.python.dataflow.new.DataFlow
4+
5+
class IgnoreDictMethod extends UnresolvedCallExpectations {
6+
override predicate unresolvedCall(CallNode call) {
7+
super.unresolvedCall(call) and
8+
not any(DataFlow::MethodCallNode methodCall |
9+
methodCall.getMethodName() in ["get", "setdefault"]
10+
).asCfgNode() = call
11+
}
12+
}

0 commit comments

Comments
 (0)