Module DataFlowDispatch
INTERNAL: Do not use.
TypeTracker based call-graph.
The overall scheme for resolving calls, is to notice that Python has different kinds of callables, and resolve those with different strategies. Currently we handle these completely separately:
- plain functions (and lambdas)
- methods on classes
- class instantiation
So we have type-trackers for each of the 3 categories above, with some considerable effort to handle different kinds of methods on classes (staticmethod, classmethod, normal), and resolving methods correctly in regards to MRO.
A goal of this library is to support modeling calls that happens by third-party
libraries. For example call_later(func, arg0, arg1, foo=val)
, and the fact that the
library might inject it’s own arguments, for example a context that will always be
passed as the actual first argument to the function. Currently the aim is to provide
enough predicates for such call_later
function to be modeled by providing
additional data-flow steps for the arguments/parameters. This means we cannot have
any special logic that requires an AST call to be made before we care to figure out
what callable this call might end up targeting.
Specifically this means that we cannot use type-backtrackers from the function of a
CallNode
, since there is no CallNode
to backtrack from for func
in the example
above.
Note: This hasn’t been 100% realized yet, so we don’t currently expose a predicate to ask what targets any data-flow node has. But it’s still the plan to do this!
Import path
import semmle.python.dataflow.new.internal.DataFlowDispatch
Imports
Predicates
attrReadTracker | Gets a reference to the attribute read |
classInstanceTracker | Gets a reference to an instance of the class |
classTracker | Gets a reference to the class |
clsArgumentTracker | Gets a reference to the enclosing class |
findFunctionAccordingToMro | Gets a potential definition of the function |
findFunctionAccordingToMroKnownStartingClass | Gets a potential definition of the function |
functionTracker | Gets a reference to the function |
getADirectSubclass | Gets a direct subclass of the argument |
getADirectSuperclass | Gets a direct superclass of the argument |
getAnOutNode | Gets a node that can read the value returned from |
getCallArg | Gets the argument |
getNextClassInMroKnownStartingClass | Gets a class that, from an approximated MRO calculation, might be the next class after |
hasContextmanagerDecorator | Holds if the function |
hasPropertyDecorator | Holds if the function |
invokedFunctionFromClassConstruction | Gets a function, either |
isClassmethod | Holds if the function |
isStaticmethod | Holds if the function |
normalCallArg | Holds if the argument of |
parameterMatch | Holds if arguments at position |
resolveCall | Holds if |
resolveClassCall | Holds when |
resolveClassInstanceCall | Holds when |
selfTracker | Gets a reference to the |
superCallNoArgumentTracker | Gets a reference to the result of calling |
superCallTwoArgumentTracker | Gets a reference to the result of calling |
viableCallable | Gets a viable run-time target for the call |
Classes
ArgumentPosition | An argument position. |
CallType | A type of call. |
CapturedVariablesArgumentNode | A synthetic argument representing the values of the variables captured by the callable being called. This argument represents a single object where all the values are stored as attributes. This is also known as the environment part of a closure. |
DataFlowCall | A call that is taken into account by the global data flow computation. |
DataFlowCallable | A callable. |
DataFlowClassmethod | A classmethod. |
DataFlowFunction | A callable function. |
DataFlowMethod | A method. |
DataFlowModuleScope | A module. This is not actually a callable, but we need this so a |
DataFlowPlainFunction | A plain (non-method) function. |
DataFlowStaticmethod | A staticmethod. |
ExtractedDataFlowCall | A call found in the program source (as opposed to a synthesised call). |
ExtractedReturnNode | A data flow node that represents a value returned by a callable. |
FlowSummaryNode | A data-flow node used to model flow summaries. |
LibraryCallable | A callable defined in library code, identified by a unique string. |
LibraryCallableValue | |
NormalCall | A resolved call in source code with an underlying |
OutNode | A data-flow node that represents the output of a call. |
ParameterNodeImpl | The value of a parameter at function entry, viewed as a node in a data flow graph. |
ParameterPosition | A parameter position. |
PotentialLibraryCall | A potential call to a summarized callable, a |
ReturnKind | A return kind. A return kind describes how a value can be returned from a callable. For Python, this is simply a method return. |
ReturnNode | A data flow node that represents a value returned by a callable. |
SummaryCall | A synthesized call inside a callable with a flow summary. |
SummaryParameterNode | A parameter for a library callable with a flow summary. |
SynthCapturedVariablesParameterNode | A synthetic parameter representing the values of the variables captured by the callable being called. This parameter represents a single object where all the values are stored as attributes. This is also known as the environment part of a closure. |
YieldNodeInContextManagerFunction | A data flow node that represents the value yielded by a callable with a |