Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit b513871

Browse files
committed
Python: add consistency exclusions
1 parent c054ba6 commit b513871

2 files changed

Lines changed: 32 additions & 0 deletions

File tree

python/ql/consistency-queries/DataFlowConsistency.ql

Lines changed: 18 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -44,6 +44,24 @@ private module Input implements InputSig<PythonDataFlow> {
4444
)
4545
}
4646

47+
predicate uniqueEnclosingCallableExclude(Node n) {
48+
// `CaptureNode`s miss enclosing calables in some cases.
49+
exists(Function func |
50+
func = n.(CaptureNode).getSynthesizedCaptureNode().getEnclosingCallable()
51+
|
52+
// This can happen if `func` is a comprehension.
53+
// In that case, there is no associated DataFlowCallable.
54+
not exists(func.getDefinition())
55+
or
56+
func.getADecorator().(Name).getId() = "property"
57+
)
58+
or
59+
// We only have a selection of valid callables.
60+
// For instance, we do not have classes as `DataFlowCallable`s.
61+
not n.(CaptureNode).getSynthesizedCaptureNode().getEnclosingCallable() instanceof Function and
62+
not n.(CaptureNode).getSynthesizedCaptureNode().getEnclosingCallable() instanceof Module
63+
}
64+
4765
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) {
4866
not exists(call.getLocation().getFile().getRelativePath())
4967
}

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

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -40,6 +40,20 @@ private module Input implements InputSig<PythonDataFlow> {
4040
)
4141
}
4242

43+
predicate uniqueEnclosingCallableExclude(Node n) {
44+
// `CaptureNode`s miss enclosing calables in some cases.
45+
exists(Function func |
46+
func = n.(CaptureNode).getSynthesizedCaptureNode().getEnclosingCallable()
47+
|
48+
// This can happen if `func` is a comprehension.
49+
// In that case, there is no associated DataFlowCallable.
50+
not exists(func.getDefinition())
51+
)
52+
or
53+
// We do not have classes as `DataFlowCallable`s.
54+
n.(CaptureNode).getSynthesizedCaptureNode().getEnclosingCallable() instanceof Class
55+
}
56+
4357
predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) {
4458
not exists(call.getLocation().getFile().getRelativePath())
4559
}

0 commit comments

Comments
 (0)