class documentation

Virtual machine that records all function calls.

Method __init__ Construct a TypegraphVirtualMachine.
Method analyze Undocumented
Method analyze_class Undocumented
Method analyze_function Undocumented
Method analyze_method_var Undocumented
Method analyze_toplevel Undocumented
Method bind_method Undocumented
Method call_function_with_args Call a function.
Method call_init Undocumented
Method call_with_fake_args Attempt to call the given function with made-up arguments.
Method compute_types Undocumented
Method create_kwargs Undocumented
Method create_method_arguments Create arguments for the given method.
Method create_varargs Undocumented
Method init_class Instantiate a class, and also call __init__.
Method maybe_analyze_method Undocumented
Method pytd_classes_for_call_traces Undocumented
Method pytd_classes_for_unknowns Undocumented
Method pytd_for_types Undocumented
Method pytd_functions_for_call_traces Undocumented
Method reinitialize_if_initialized Undocumented
Method trace_call Add an entry into the call trace.
Method trace_classdef Undocumented
Method trace_functiondef Undocumented
Method trace_unknown Fired whenever we create a variable containing 'Unknown'.
Static Method _call_traces_to_function Undocumented
Method _call_function_in_frame Undocumented
Method _call_init_on_binding Undocumented
Method _call_method Undocumented
Method _check_return Undocumented
Method _instantiate_binding Instantiate a class binding.
Method _instantiate_var Build an (dummy) instance from a class, for analyzing it.
Method _is_future_feature Undocumented
Method _is_typing_member Undocumented
Method _mark_maybe_missing_members Set maybe_missing_members to True on these values and their type params.
Method _maybe_fix_classmethod_cls_arg Undocumented
Method _maybe_instantiate_binding_directly Undocumented
Method _should_analyze_as_interpreter_function Undocumented
Method _skip_definition_export Undocumented
Constant _CONSTRUCTORS Undocumented
Instance Variable _analyzed_classes Undocumented
Instance Variable _analyzed_functions Undocumented
Instance Variable _analyzing Undocumented
Instance Variable _calls Undocumented
Instance Variable _initialized_instances Undocumented
Instance Variable _instance_cache Undocumented
Instance Variable _interpreter_classes Undocumented
Instance Variable _interpreter_functions Undocumented
Instance Variable _maximum_depth Undocumented
Instance Variable _method_calls Undocumented
Instance Variable _unknowns Undocumented

Inherited from VirtualMachine:

Exception VirtualMachineRecursionError Undocumented
Method binary_operator Undocumented
Method byte_ASYNC_GEN_WRAP Undocumented
Method byte_BEFORE_ASYNC_WITH Implementation of the BEFORE_ASYNC_WITH opcode.
Method byte_BEFORE_WITH Undocumented
Method byte_BEGIN_FINALLY Undocumented
Method byte_BINARY_ADD Undocumented
Method byte_BINARY_AND Undocumented
Method byte_BINARY_FLOOR_DIVIDE Undocumented
Method byte_BINARY_LSHIFT Undocumented
Method byte_BINARY_MATRIX_MULTIPLY Undocumented
Method byte_BINARY_MODULO Undocumented
Method byte_BINARY_MULTIPLY Undocumented
Method byte_BINARY_OP Undocumented
Method byte_BINARY_OR Undocumented
Method byte_BINARY_POWER Undocumented
Method byte_BINARY_RSHIFT Undocumented
Method byte_BINARY_SUBSCR Undocumented
Method byte_BINARY_SUBTRACT Undocumented
Method byte_BINARY_TRUE_DIVIDE Undocumented
Method byte_BINARY_XOR Undocumented
Method byte_BREAK_LOOP Undocumented
Method byte_BUILD_CONST_KEY_MAP Undocumented
Method byte_BUILD_LIST Undocumented
Method byte_BUILD_LIST_UNPACK Undocumented
Method byte_BUILD_MAP Build a dictionary.
Method byte_BUILD_MAP_UNPACK Undocumented
Method byte_BUILD_MAP_UNPACK_WITH_CALL Undocumented
Method byte_BUILD_SET Undocumented
Method byte_BUILD_SET_UNPACK Undocumented
Method byte_BUILD_SLICE Undocumented
Method byte_BUILD_STRING Undocumented
Method byte_BUILD_TUPLE Undocumented
Method byte_BUILD_TUPLE_UNPACK Undocumented
Method byte_BUILD_TUPLE_UNPACK_WITH_CALL Undocumented
Method byte_CACHE Undocumented
Method byte_CALL Undocumented
Method byte_CALL_FINALLY Undocumented
Method byte_CALL_FUNCTION Undocumented
Method byte_CALL_FUNCTION_EX Call a function.
Method byte_CALL_FUNCTION_KW Undocumented
Method byte_CALL_FUNCTION_VAR Undocumented
Method byte_CALL_FUNCTION_VAR_KW Undocumented
Method byte_CALL_METHOD Undocumented
Method byte_CHECK_EG_MATCH Undocumented
Method byte_CHECK_EXC_MATCH Undocumented
Method byte_COMPARE_OP Undocumented
Method byte_CONTAINS_OP Undocumented
Method byte_CONTINUE_LOOP Undocumented
Method byte_COPY Undocumented
Method byte_COPY_DICT_WITHOUT_KEYS Undocumented
Method byte_COPY_FREE_VARS Undocumented
Method byte_DELETE_ATTR Undocumented
Method byte_DELETE_DEREF Undocumented
Method byte_DELETE_FAST Undocumented
Method byte_DELETE_GLOBAL Undocumented
Method byte_DELETE_NAME Undocumented
Method byte_DELETE_SUBSCR Undocumented
Method byte_DICT_MERGE Undocumented
Method byte_DICT_UPDATE Pops top-of-stack and uses it to update the dict at stack[op.arg].
Method byte_DUP_TOP Undocumented
Method byte_DUP_TOP_TWO Undocumented
Method byte_END_ASYNC_FOR Undocumented
Method byte_END_FINALLY Implementation of the END_FINALLY opcode.
Method byte_FOR_ITER Undocumented
Method byte_FORMAT_VALUE Undocumented
Method byte_GEN_START Undocumented
Method byte_GET_AITER Implementation of the GET_AITER opcode.
Method byte_GET_ANEXT Implementation of the GET_ANEXT opcode.
Method byte_GET_AWAITABLE Implementation of the GET_AWAITABLE opcode.
Method byte_GET_ITER Get the iterator for an object.
Method byte_GET_LEN Undocumented
Method byte_GET_YIELD_FROM_ITER Implementation of the GET_YIELD_FROM_ITER opcode.
Method byte_IMPORT_FROM IMPORT_FROM is mostly like LOAD_ATTR but doesn't pop the container.
Method byte_IMPORT_NAME Import a single module.
Method byte_IMPORT_STAR Pops a module and stores all its contents in locals().
Method byte_INPLACE_ADD Undocumented
Method byte_INPLACE_AND Undocumented
Method byte_INPLACE_FLOOR_DIVIDE Undocumented
Method byte_INPLACE_LSHIFT Undocumented
Method byte_INPLACE_MATRIX_MULTIPLY Undocumented
Method byte_INPLACE_MODULO Undocumented
Method byte_INPLACE_MULTIPLY Undocumented
Method byte_INPLACE_OR Undocumented
Method byte_INPLACE_POWER Undocumented
Method byte_INPLACE_RSHIFT Undocumented
Method byte_INPLACE_SUBTRACT Undocumented
Method byte_INPLACE_TRUE_DIVIDE Undocumented
Method byte_INPLACE_XOR Undocumented
Method byte_IS_OP Undocumented
Method byte_JUMP_ABSOLUTE Undocumented
Method byte_JUMP_BACKWARD Undocumented
Method byte_JUMP_BACKWARD_NO_INTERRUPT Undocumented
Method byte_JUMP_FORWARD Undocumented
Method byte_JUMP_IF_FALSE Undocumented
Method byte_JUMP_IF_FALSE_OR_POP Undocumented
Method byte_JUMP_IF_NOT_EXC_MATCH Undocumented
Method byte_JUMP_IF_TRUE Undocumented
Method byte_JUMP_IF_TRUE_OR_POP Undocumented
Method byte_KW_NAMES Undocumented
Method byte_LIST_APPEND Undocumented
Method byte_LIST_EXTEND Pops top-of-stack and uses it to extend the list at stack[op.arg].
Method byte_LIST_TO_TUPLE Convert the list at the top of the stack to a tuple.
Method byte_LOAD_ASSERTION_ERROR Undocumented
Method byte_LOAD_ATTR Pop an object, and retrieve a named attribute from it.
Method byte_LOAD_BUILD_CLASS Undocumented
Method byte_LOAD_CLASSDEREF Retrieves a value out of either locals or a closure cell.
Method byte_LOAD_CLOSURE Retrieves a value out of a cell.
Method byte_LOAD_CONST Undocumented
Method byte_LOAD_DEREF Retrieves a value out of a cell.
Method byte_LOAD_FAST Load a local. Unlike LOAD_NAME, it doesn't fall back to globals.
Method byte_LOAD_FOLDED_CONST Undocumented
Method byte_LOAD_GLOBAL Load a global variable, or fall back to trying to load a builtin.
Method byte_LOAD_METHOD Implementation of the LOAD_METHOD opcode.
Method byte_LOAD_NAME Load a name. Can be a local, global, or builtin.
Method byte_MAKE_CELL Undocumented
Method byte_MAKE_CLOSURE Make a function that binds local variables.
Method byte_MAKE_FUNCTION Create a function and push it onto the stack.
Method byte_MAP_ADD Implements the MAP_ADD opcode.
Method byte_MATCH_CLASS Implementation of the MATCH_CLASS opcode.
Method byte_MATCH_KEYS Implementation of the MATCH_KEYS opcode.
Method byte_MATCH_MAPPING Undocumented
Method byte_MATCH_SEQUENCE Undocumented
Method byte_NOP Undocumented
Method byte_POP_BLOCK Undocumented
Method byte_POP_EXCEPT Undocumented
Method byte_POP_FINALLY Implements POP_FINALLY.
Method byte_POP_JUMP_BACKWARD_IF_FALSE Undocumented
Method byte_POP_JUMP_BACKWARD_IF_NONE Undocumented
Method byte_POP_JUMP_BACKWARD_IF_NOT_NONE Undocumented
Method byte_POP_JUMP_BACKWARD_IF_TRUE Undocumented
Method byte_POP_JUMP_FORWARD_IF_FALSE Undocumented
Method byte_POP_JUMP_FORWARD_IF_NONE Undocumented
Method byte_POP_JUMP_FORWARD_IF_NOT_NONE Undocumented
Method byte_POP_JUMP_FORWARD_IF_TRUE Undocumented
Method byte_POP_JUMP_IF_FALSE Undocumented
Method byte_POP_JUMP_IF_TRUE Undocumented
Method byte_POP_TOP Undocumented
Method byte_PRECALL Undocumented
Method byte_PREP_RERAISE_STAR Undocumented
Method byte_PRINT_EXPR Undocumented
Method byte_PUSH_EXC_INFO Undocumented
Method byte_PUSH_NULL Undocumented
Method byte_RAISE_VARARGS Raise an exception.
Method byte_RERAISE Undocumented
Method byte_RESUME Undocumented
Method byte_RETURN_GENERATOR Undocumented
Method byte_RETURN_VALUE Get and check the return value.
Method byte_ROT_FOUR Undocumented
Method byte_ROT_N Undocumented
Method byte_ROT_THREE Undocumented
Method byte_ROT_TWO Undocumented
Method byte_SEND Undocumented
Method byte_SET_ADD Undocumented
Method byte_SET_UPDATE Undocumented
Method byte_SETUP_ANNOTATIONS Sets up variable annotations in locals().
Method byte_SETUP_ASYNC_WITH Undocumented
Method byte_SETUP_EXCEPT Undocumented
Method byte_SETUP_FINALLY Implements the SETUP_FINALLY opcode.
Method byte_SETUP_LOOP Undocumented
Method byte_SETUP_WITH Starts a 'with' statement. Will push a block.
Method byte_STORE_ANNOTATION Implementation of the STORE_ANNOTATION opcode.
Method byte_STORE_ATTR Store an attribute.
Method byte_STORE_DEREF Stores a value in a closure cell.
Method byte_STORE_FAST Undocumented
Method byte_STORE_GLOBAL Undocumented
Method byte_STORE_NAME Undocumented
Method byte_STORE_SUBSCR Implement obj[subscr] = val.
Method byte_SWAP Undocumented
Method byte_UNARY_INVERT Undocumented
Method byte_UNARY_NEGATIVE Undocumented
Method byte_UNARY_NOT Implement the UNARY_NOT bytecode.
Method byte_UNARY_POSITIVE Undocumented
Method byte_UNPACK_EX Undocumented
Method byte_UNPACK_SEQUENCE Undocumented
Method byte_WITH_CLEANUP_FINISH Called to finish cleaning up a with block.
Method byte_WITH_CLEANUP_START Called to start cleaning up a with block. Calls the exit handlers etc.
Method byte_WITH_EXCEPT_START Undocumented
Method byte_YIELD_FROM Implementation of the YIELD_FROM opcode.
Method byte_YIELD_VALUE Yield a value from a generator.
Method call_function_from_stack Pop arguments for a function and call it.
Method call_function_with_state Call a function with the given state.
Method compile_src Compile the given source code.
Method del_attr Delete an attribute.
Method del_subscr Undocumented
Method expand_bool_result Common functionality for 'is' and 'is not'.
Method flatten_late_annotation Undocumented
Method generate_late_annotations Undocumented
Method get_all_named_vars Undocumented
Method get_globals_dict Get a real python dict of the globals.
Method get_var_name Get the python variable name corresponding to a Variable.
Method import_module Import a module and return the module object or None.
Method inplace_operator Undocumented
Method is_at_maximum_depth Undocumented
Method is_setup_except Check whether op is equivalent to a SETUP_EXCEPT opcode.
Method load_attr Try loading an attribute, and report errors.
Method load_attr_noerror Try loading an attribute, ignore errors.
Method load_builtin Undocumented
Method load_constant Undocumented
Method load_from Load an item out of locals, globals, or builtins.
Method load_global Undocumented
Method load_local Called when a local is loaded onto the stack.
Method load_special_builtin Undocumented
Method make_frame Create a new frame object, using the given args, globals and locals.
Method pop_frame Undocumented
Method pop_kwargs Retrieve a kwargs dictionary from the stack. Used by call_function.
Method pop_varargs Retrieve a varargs tuple from the stack. Used by call_function.
Method push_abstract_exception Undocumented
Method push_frame Undocumented
Method remaining_depth Undocumented
Method resume_frame Undocumented
Method run_bytecode Run the given bytecode.
Method run_frame Run a frame (typically belonging to a method).
Method run_instruction Run a single bytecode instruction.
Method run_program Run the code and return the CFG nodes.
Method set_var_name Undocumented
Method simple_stack Get a stack of simple frames.
Method stack Get a frame stack for the given function for error reporting.
Method store_attr Set an attribute on an object.
Method store_jump Undocumented
Method store_local Called when a local is written.
Method store_subscr Undocumented
Method trace_opcode Record trace data for other tools to use.
Method unary_operator Undocumented
Instance Variable annotated_locals Undocumented
Instance Variable ctx Undocumented
Instance Variable filename Undocumented
Instance Variable frame Undocumented
Instance Variable frames Undocumented
Instance Variable functions_type_params_check Undocumented
Instance Variable has_unknown_wildcard_imports Undocumented
Instance Variable late_annotations Undocumented
Instance Variable loaded_overlays Undocumented
Instance Variable local_ops Undocumented
Instance Variable opcode_traces Undocumented
Property current_annotated_locals Undocumented
Property current_line Undocumented
Property current_local_ops Undocumented
Property current_opcode Undocumented
Method _apply_annotation Applies the type annotation, if any, associated with this object.
Method _attribute_error_detection Undocumented
Method _call Undocumented
Method _check_test_assert Narrow the types of variables based on test assertions.
Method _cmp_in Implementation of CMP_IN/CMP_NOT_IN.
Method _cmp_is_always_supported Checks if the comparison should always succeed.
Method _cmp_rel Implementation of relational operators CMP_(LT|LE|EQ|NE|GE|GT).
Method _coerce_to_bool Coerce the values in a variable to bools.
Method _compare_op Pops and compares the top two stack values and pushes a boolean.
Method _convert_kw_defaults Undocumented
Method _data_is_none Undocumented
Method _del_name Called when a local or global is deleted.
Method _delete_item Undocumented
Method _filter_none_and_paste_bindings Paste the bindings into var, filtering out false positives on None.
Method _get_aiter Get an async iterator from an object.
Method _get_extra_closure_args Get closure annotations and defaults from the stack.
Method _get_extra_function_args Get function annotations and defaults from the stack.
Method _get_iter Get an iterator from a sequence.
Method _get_literal_sequence Helper function for _unpack_sequence.
Method _get_type_of_attr_to_store Grabs the __annotations__ dict, if any, with the attribute type.
Method _has_strict_none_origins Whether the binding has any possible origins, with None filtering.
Method _import_module Import the module and return the module object.
Method _instantiate_exception Instantiate an exception type.
Method _is_classmethod_cls_arg True if var is the first arg of a class method in the current frame.
Method _is_private Undocumented
Method _load_annotation Undocumented
Method _maybe_load_overlay Check if a module path is in the overlay dictionary.
Method _name_error_or_late_annotation Returns a late annotation or returns Any and logs a name error.
Method _narrow Narrow a variable by removing bindings that do not satisfy pred.
Method _pop_and_store Pop a value off the stack and store it in a variable.
Method _process_annotations Process any type annotations in the named value.
Method _record_annotation Undocumented
Method _record_annotation_dict_store Record a store_subscr to an __annotations__ dict.
Method _record_local Record a type annotation on a local variable.
Method _replace_abstract_exception Replace unknowns added by push_abstract_exception with precise values.
Method _restructure_tuple Collapse the middle part of a tuple into a List variable.
Method _retrieve_attr Load an attribute from an object.
Method _revert_state_to Undocumented
Method _set_frame_return Undocumented
Method _set_type_from_assert_isinstance Undocumented
Method _setup_except Sets up an except block.
Method _store_new_var_in_local Assign a new var to a variable in locals.
Method _store_value Store 'value' under 'name'.
Method _suppress_opcode_tracing Undocumented
Method _unpack_sequence Pops a tuple (or other iterable) and pushes it onto the VM's stack.
Method _update_annotations_dict Undocumented
Method _var_is_none Undocumented
Method _with_cleanup_start Implements WITH_CLEANUP_START before Python 3.8.
Method _with_cleanup_start_3_8 Implements WITH_CLEANUP_START in Python 3.8+.
Instance Variable _branch_tracker Undocumented
Instance Variable _director Undocumented
Instance Variable _importing Undocumented
Instance Variable _late_annotations_stack Undocumented
Instance Variable _trace_opcodes Undocumented
Instance Variable _var_names Undocumented
def __init__(self, *args, **kwargs): (source)

Construct a TypegraphVirtualMachine.

def analyze(self, node, defs, maximum_depth): (source)

Undocumented

def analyze_class(self, node, val): (source)

Undocumented

def analyze_function(self, node0, val): (source)

Undocumented

def analyze_method_var(self, node0, name, var, cls): (source)

Undocumented

def analyze_toplevel(self, node, defs): (source)

Undocumented

def bind_method(self, node, methodvar, instance_var): (source)

Undocumented

def call_function_with_args(self, node, val, args): (source)

Call a function. Args: node: The given node. val: A cfg.Binding containing the function. args: A function.Args object. Returns: A tuple of (1) a node and (2) a cfg.Variable of the return value.

def call_init(self, node, instance): (source)

Undocumented

def call_with_fake_args(self, node0, funcv): (source)

Attempt to call the given function with made-up arguments.

def compute_types(self, defs): (source)

Undocumented

def create_kwargs(self, node): (source)

Undocumented

def create_method_arguments(self, node, method, use_defaults=False): (source)

Create arguments for the given method. Creates Unknown objects as arguments for the given method. Note that we don't need to take parameter annotations into account as InterpreterFunction.call() will take care of that. Args: node: The current node. method: An abstract.InterpreterFunction. use_defaults: Whether to use parameter defaults for arguments. When True, unknown arguments are created with force=False, as it is fine to use Unsolvable rather than Unknown objects for type-checking defaults. Returns: A tuple of a node and a function.Args object.

def create_varargs(self, node): (source)

Undocumented

def init_class(self, node, cls, container=None, extra_key=None): (source)

Instantiate a class, and also call __init__. Calling __init__ can be expensive, so this method caches its created instances. If you don't need __init__ called, use cls.instantiate instead. Args: node: The current node. cls: The class to instantiate. container: Optionally, a container to pass to the class's instantiate() method, so that type parameters in the container's template are instantiated to TypeParameterInstance. extra_key: Optionally, extra information about the location at which the instantion occurs. By default, this method keys on the current opcode and the class, which sometimes isn't enough to disambiguate callers that shouldn't get back the same cached instance. Returns: A tuple of node and instance variable.

def maybe_analyze_method(self, node, val, cls=None): (source)

Undocumented

def pytd_classes_for_call_traces(self): (source)

Undocumented

def pytd_classes_for_unknowns(self): (source)

Undocumented

def pytd_for_types(self, defs): (source)

Undocumented

def pytd_functions_for_call_traces(self): (source)

Undocumented

def reinitialize_if_initialized(self, node, instance): (source)

Undocumented

def trace_call(self, node, func, sigs, posargs, namedargs, result): (source)

Add an entry into the call trace. Args: node: The CFG node right after this function call. func: A cfg.Binding of a function that was called. sigs: The signatures that the function might have been called with. posargs: The positional arguments, an iterable over cfg.Variable. namedargs: The keyword arguments, a dict mapping str to cfg.Variable. result: A Variable of the possible result values.

def trace_classdef(self, c): (source)
def trace_functiondef(self, f): (source)
def trace_unknown(self, name, unknown_binding): (source)

Fired whenever we create a variable containing 'Unknown'.

@staticmethod
def _call_traces_to_function(call_traces, name_transform=(lambda x: x)): (source)

Undocumented

def _call_function_in_frame(self, node, val, args, kwargs, starargs, starstarargs): (source)

Undocumented

def _call_init_on_binding(self, node, b): (source)

Undocumented

def _call_method(self, node, binding, method_name): (source)

Undocumented

def _check_return(self, node, actual, formal): (source)
def _instantiate_binding(self, node0, cls, container, instantiate_directly): (source)

Instantiate a class binding.

def _instantiate_var(self, node, clsv, container, instantiate_directly): (source)

Build an (dummy) instance from a class, for analyzing it.

def _is_future_feature(self, name, var): (source)

Undocumented

def _is_typing_member(self, name, var): (source)

Undocumented

def _mark_maybe_missing_members(self, values): (source)

Set maybe_missing_members to True on these values and their type params. Args: values: A list of BaseValue objects. On every instance among the values, recursively set maybe_missing_members to True on the instance and its type parameters.

def _maybe_fix_classmethod_cls_arg(self, node, cls, func, args): (source)

Undocumented

def _maybe_instantiate_binding_directly(self, node0, cls, container, instantiate_directly): (source)

Undocumented

def _should_analyze_as_interpreter_function(self, data): (source)

Undocumented

def _skip_definition_export(self, name, var): (source)

Undocumented

_CONSTRUCTORS: tuple[str, ...] = (source)

Undocumented

Value
('__new__', '__init__')
_analyzed_classes = (source)

Undocumented

_analyzed_functions = (source)

Undocumented

Undocumented

_initialized_instances = (source)

Undocumented

Undocumented

_interpreter_classes: list = (source)

Undocumented

_interpreter_functions: list = (source)

Undocumented

_maximum_depth = (source)
_method_calls = (source)

Undocumented

_unknowns: dict = (source)

Undocumented