CodeQL library for Python
codeql/python-all 0.11.11-dev (changelog, source)
Search

Class ModuleVariableNode

A data flow node corresponding to a module-level (global) variable that is accessed outside of the module scope.

Global variables may appear twice in the data flow graph, as both EssaNodes and ModuleVariableNodes. The former is used to represent data flow between global variables as it occurs during module initialization, and the latter is used to represent data flow via global variable reads and writes during run-time.

It is possible for data to flow from assignments made at module initialization time to reads made at run-time, but not vice versa. For example, there will be flow from SOURCE to SINK in the following snippet:

g = SOURCE

def foo():
    SINK(g)

but not the other way round:

SINK(g)

def bar()
    global g
    g = SOURCE

Data flow through ModuleVariableNodes is represented as jumpSteps, and so any write of a global variable can flow to any read of the same variable.

Import path

import semmle.python.dataflow.new.internal.DataFlowPublic

Direct supertypes

Indirect supertypes

Fields

Predicates

getADefiningWrite

Gets the possible values of the variable at the end of import time

getARead

Gets a node that reads this variable.

getAWrite

Gets an EssaNode that corresponds to an assignment of this global variable.

getEnclosingCallable

Gets the enclosing callable of this node.

getLocation

Gets the location of this node

getModule

Gets the module in which this variable appears.

getScope

Gets the scope of this node.

getVariable

Gets the global variable corresponding to this node.

toString

Gets a textual representation of this element.

Inherited predicates

asCfgNode

Gets the control-flow node corresponding to this node, if any.

from Node
asExpr

Gets the expression corresponding to this node, if any.

from Node
getALocalSource

Gets a local source node from which data may flow to this node in zero or more local data-flow steps.

from Node
hasLocationInfo

Holds if this element is at the specified location. The location spans column startcolumn of line startline to column endcolumn of line endline in file filepath. For more information, see Locations.

from Node

Charpred