|
| 1 | +import python |
| 2 | +import semmle.python.dataflow.new.DataFlow::DataFlow |
| 3 | +import semmle.python.dataflow.new.internal.DataFlowPrivate |
| 4 | +import semmle.python.dataflow.new.internal.DataFlowImplConsistency::Consistency |
| 5 | + |
| 6 | +private class MyConsistencyConfiguration extends ConsistencyConfiguration { |
| 7 | + override predicate argHasPostUpdateExclude(ArgumentNode n) { |
| 8 | + exists(ArgumentPosition apos | n.argumentOf(_, apos) and apos.isStarArgs(_)) |
| 9 | + or |
| 10 | + exists(ArgumentPosition apos | n.argumentOf(_, apos) and apos.isDictSplat()) |
| 11 | + } |
| 12 | + |
| 13 | + override predicate reverseReadExclude(Node n) { |
| 14 | + // since `self`/`cls` parameters can be marked as implicit argument to `super()`, |
| 15 | + // they will have PostUpdateNodes. We have a read-step from the synthetic `**kwargs` |
| 16 | + // parameter, but dataflow-consistency queries should _not_ complain about there not |
| 17 | + // being a post-update node for the synthetic `**kwargs` parameter. |
| 18 | + n instanceof SynthDictSplatParameterNode |
| 19 | + } |
| 20 | + |
| 21 | + override predicate uniqueParameterNodePositionExclude( |
| 22 | + DataFlowCallable c, ParameterPosition pos, Node p |
| 23 | + ) { |
| 24 | + // For normal parameters that can both be passed as positional arguments or keyword |
| 25 | + // arguments, we currently have parameter positions for both cases.. |
| 26 | + // |
| 27 | + // TODO: Figure out how bad breaking this consistency check is |
| 28 | + exists(Function func, Parameter param | |
| 29 | + c.getScope() = func and |
| 30 | + p = parameterNode(param) and |
| 31 | + c.getParameter(pos) = p and |
| 32 | + param = func.getArg(_) and |
| 33 | + param = func.getArgByName(_) |
| 34 | + ) |
| 35 | + } |
| 36 | + |
| 37 | + override predicate uniqueCallEnclosingCallableExclude(DataFlowCall call) { |
| 38 | + not exists(call.getLocation().getFile().getRelativePath()) |
| 39 | + } |
| 40 | + |
| 41 | + override predicate identityLocalStepExclude(Node n) { |
| 42 | + not exists(n.getLocation().getFile().getRelativePath()) |
| 43 | + } |
| 44 | +} |
0 commit comments