mirror of
https://github.com/github/codeql.git
synced 2025-12-24 04:36:35 +01:00
Python: Don't report get/setdefault as unresolved calls for dict tests
This commit is contained in:
@@ -9,14 +9,17 @@ class UnresolvedCallExpectations extends InlineExpectationsTest {
|
|||||||
|
|
||||||
override string getARelevantTag() { result = "unresolved_call" }
|
override string getARelevantTag() { result = "unresolved_call" }
|
||||||
|
|
||||||
|
predicate unresolvedCall(CallNode call) {
|
||||||
|
not exists(DataFlowPrivate::DataFlowCall dfc |
|
||||||
|
exists(dfc.getCallable()) and dfc.getNode() = call
|
||||||
|
) and
|
||||||
|
not DataFlowPrivate::resolveClassCall(call, _) and
|
||||||
|
not call = API::builtin(_).getACall().asCfgNode()
|
||||||
|
}
|
||||||
|
|
||||||
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
override predicate hasActualResult(Location location, string element, string tag, string value) {
|
||||||
exists(location.getFile().getRelativePath()) and
|
exists(location.getFile().getRelativePath()) and
|
||||||
exists(CallNode call |
|
exists(CallNode call | this.unresolvedCall(call) |
|
||||||
not exists(DataFlowPrivate::DataFlowCall dfc |
|
|
||||||
exists(dfc.getCallable()) and dfc.getNode() = call
|
|
||||||
) and
|
|
||||||
not DataFlowPrivate::resolveClassCall(call, _) and
|
|
||||||
not call = API::builtin(_).getACall().asCfgNode() and
|
|
||||||
location = call.getLocation() and
|
location = call.getLocation() and
|
||||||
tag = "unresolved_call" and
|
tag = "unresolved_call" and
|
||||||
value = prettyExpr(call.getNode()) and
|
value = prettyExpr(call.getNode()) and
|
||||||
|
|||||||
@@ -1,2 +1,12 @@
|
|||||||
import python
|
import python
|
||||||
import experimental.dataflow.TestUtil.UnresolvedCalls
|
import experimental.dataflow.TestUtil.UnresolvedCalls
|
||||||
|
private import semmle.python.dataflow.new.DataFlow
|
||||||
|
|
||||||
|
class IgnoreDictMethod extends UnresolvedCallExpectations {
|
||||||
|
override predicate unresolvedCall(CallNode call) {
|
||||||
|
super.unresolvedCall(call) and
|
||||||
|
not any(DataFlow::MethodCallNode methodCall |
|
||||||
|
methodCall.getMethodName() in ["get", "setdefault"]
|
||||||
|
).asCfgNode() = call
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user