class documentation

Functions for creating the classes in abstract.py.

Exception TypeParameterError Undocumented
Method __init__ Undocumented
Method build_bool Undocumented
Method build_collection_of_type Create a collection Typ[T] with T derived from the given variable.
Method build_content Undocumented
Method build_int Undocumented
Method build_list Create a VM list from the given sequence.
Method build_list_of_type Create a VM list with element type derived from the given variable.
Method build_map Create an empty VM dict.
Method build_nonatomic_string Undocumented
Method build_none Undocumented
Method build_set Create a VM set from the given sequence.
Method build_slice Undocumented
Method build_string Undocumented
Method build_tuple Create a VM tuple from the given sequence.
Method constant_name Undocumented
Method constant_to_value Like constant_to_var, but convert to an abstract.BaseValue.
Method constant_to_var Convert a constant to a Variable.
Method convert_pytd_function Undocumented
Method create_new_unknown Create a new variable containing unknown.
Method get_element_type Extract the element type of a vararg or kwarg.
Method get_maybe_abstract_instance Get an instance of the same type as the given data, abstract if possible.
Method make_namedtuple Make a namedtuple class from a pytd class.
Method make_namedtuple_builder Make a namedtuple builder.
Method make_typed_dict Make a typed dict from a pytd class.
Method make_typed_dict_builder Make a typed dict builder.
Method merge_classes Merge the classes of the given instances.
Method merge_values Merge a collection of values into a single one.
Method name_to_value Undocumented
Method tuple_to_value Create a VM tuple from the given sequence.
Method value_to_constant Undocumented
Method widen_type Widen a tuple to an iterable, or a dict to a mapping.
Instance Variable async_generator_type Undocumented
Instance Variable awaitable_type Undocumented
Instance Variable bool_type Undocumented
Instance Variable bool_values Undocumented
Instance Variable bytes_type Undocumented
Instance Variable coroutine_type Undocumented
Instance Variable dict_type Undocumented
Instance Variable ellipsis Undocumented
Instance Variable empty Undocumented
Instance Variable false Undocumented
Instance Variable frozenset_type Undocumented
Instance Variable function_type Undocumented
Instance Variable generator_type Undocumented
Instance Variable int_type Undocumented
Instance Variable iterator_type Undocumented
Instance Variable list_type Undocumented
Instance Variable module_type Undocumented
Instance Variable no_return Undocumented
Instance Variable none Undocumented
Instance Variable none_type Undocumented
Instance Variable object_type Undocumented
Instance Variable primitive_class_instances Undocumented
Instance Variable primitive_class_names Undocumented
Instance Variable primitive_classes Undocumented
Instance Variable set_type Undocumented
Instance Variable str_type Undocumented
Instance Variable super_type Undocumented
Instance Variable true Undocumented
Instance Variable tuple_type Undocumented
Instance Variable type_type Undocumented
Instance Variable unsolvable Undocumented
Method _apply_metadata_annotations Undocumented
Method _constant_to_value Create a BaseValue that represents a python constant.
Method _copy_type_parameters Undocumented
Method _create_module Undocumented
Method _create_new_unknown_value Undocumented
Method _get_literal_value Extract and convert the value of a pytd.Literal.
Method _load_late_type Resolve a late type, possibly by loading a module.
Method _load_late_type_module Undocumented
Method _maybe_load_from_overlay Undocumented
Method _special_constant_to_value Special-case construction of some pytd values.
Method _type_to_name Convert a type to its name.
Instance Variable _convert_cache Undocumented
Instance Variable _resolved_late_types Undocumented

Inherited from ContextWeakrefMixin:

Class Variable __slots__ Undocumented
Instance Variable ctx_weakref Undocumented
Property ctx Undocumented
def __init__(self, ctx): (source)
def build_bool(self, node, value=None): (source)

Undocumented

def build_collection_of_type(self, node, typ, var): (source)

Create a collection Typ[T] with T derived from the given variable.

def build_content(self, elements): (source)

Undocumented

def build_int(self, node): (source)

Undocumented

def build_list(self, node, content): (source)

Create a VM list from the given sequence.

def build_list_of_type(self, node, var): (source)

Create a VM list with element type derived from the given variable.

def build_map(self, node): (source)

Create an empty VM dict.

def build_nonatomic_string(self, node): (source)

Undocumented

def build_none(self, node): (source)

Undocumented

def build_set(self, node, content): (source)

Create a VM set from the given sequence.

def build_slice(self, node, start, stop, step=None): (source)

Undocumented

def build_string(self, node, s): (source)

Undocumented

def build_tuple(self, node, content): (source)

Create a VM tuple from the given sequence.

def constant_name(self, constant_type): (source)

Undocumented

def constant_to_value(self, pyval, subst=None, node=None): (source)

Like constant_to_var, but convert to an abstract.BaseValue. This also memoizes the results. We don't memoize on name, as builtin types like str or list might be reinitialized under different names (e.g. "param 1"), but we want the canonical name and type. We *do* memoize on the type as well, to make sure that e.g. "1.0" and "1" get converted to different constants. Memoization is an optimization, but an important one - mapping constants like "None" to the same AbstractValue greatly simplifies the cfg structures we're building. Args: pyval: The constant to convert. subst: The current type parameters. node: The current CFG node. (For instances) Returns: The converted constant. (Instance of BaseValue)

def constant_to_var(self, pyval, subst=None, node=None, source_sets=None, discard_concrete_values=False): (source)

Convert a constant to a Variable. This converts a constant to a cfg.Variable. Unlike constant_to_value, it can handle things that need to be represented as a Variable with multiple possible values (i.e., a union type), like pytd.Function. Args: pyval: The Python constant to convert. Can be a PyTD definition or a builtin constant. subst: The current type parameters. node: The current CFG node. (For instances) source_sets: An iterator over instances of SourceSet (or just tuples). discard_concrete_values: Whether concrete values should be discarded from type parameters. Returns: A cfg.Variable. Raises: TypeParameterError: if conversion is attempted on a type parameter without a substitution. ValueError: if pytype is not of a known type.

def convert_pytd_function(self, pytd_func, factory=abstract.PyTDFunction): (source)

Undocumented

def create_new_unknown(self, node, source=None, action=None, force=False): (source)

Create a new variable containing unknown.

def get_element_type(self, arg_type): (source)

Extract the element type of a vararg or kwarg.

def get_maybe_abstract_instance(self, data): (source)

Get an instance of the same type as the given data, abstract if possible. Get an abstract instance of primitive data stored as a ConcreteValue. Return any other data as-is. This is used by constant_to_var to discard concrete values that have been kept around for InterpreterFunction. Arguments: data: The data. Returns: An instance of the same type as the data, abstract if possible.

def make_namedtuple(self, name, pytd_cls, ctx): (source)

Make a namedtuple class from a pytd class.

def make_namedtuple_builder(self, ctx): (source)

Make a namedtuple builder.

def make_typed_dict(self, name, pytd_cls, ctx): (source)

Make a typed dict from a pytd class.

def make_typed_dict_builder(self, ctx): (source)

Make a typed dict builder.

def merge_classes(self, instances): (source)

Merge the classes of the given instances. Args: instances: An iterable of instances. Returns: An abstract.BaseValue created by merging the instances' classes.

def merge_values(self, values): (source)

Merge a collection of values into a single one.

def name_to_value(self, name, subst=None, ast=None): (source)

Undocumented

def tuple_to_value(self, content): (source)

Create a VM tuple from the given sequence.

def value_to_constant(self, val, constant_type): (source)

Undocumented

def widen_type(self, container): (source)

Widen a tuple to an iterable, or a dict to a mapping.

async_generator_type = (source)

Undocumented

awaitable_type = (source)

Undocumented

bool_type = (source)

Undocumented

bool_values = (source)

Undocumented

bytes_type = (source)

Undocumented

coroutine_type = (source)

Undocumented

dict_type = (source)

Undocumented

ellipsis = (source)

Undocumented

Undocumented

Undocumented

frozenset_type = (source)

Undocumented

function_type = (source)

Undocumented

generator_type = (source)

Undocumented

int_type = (source)

Undocumented

iterator_type = (source)

Undocumented

list_type = (source)

Undocumented

module_type = (source)

Undocumented

no_return = (source)

Undocumented

Undocumented

none_type = (source)

Undocumented

object_type = (source)

Undocumented

primitive_class_instances: dict = (source)

Undocumented

primitive_class_names = (source)

Undocumented

primitive_classes = (source)

Undocumented

set_type = (source)

Undocumented

str_type = (source)

Undocumented

super_type = (source)

Undocumented

Undocumented

tuple_type = (source)

Undocumented

type_type = (source)

Undocumented

unsolvable = (source)

Undocumented

def _apply_metadata_annotations(self, typ, annotations): (source)

Undocumented

def _constant_to_value(self, pyval, subst, get_node): (source)

Create a BaseValue that represents a python constant. This supports both constant from code constant pools and PyTD constants such as classes. This also supports builtin python objects such as int and float. Args: pyval: The python or PyTD value to convert. subst: The current type parameters. get_node: A getter function for the current node. Returns: A Value that represents the constant, or None if we couldn't convert. Raises: NotImplementedError: If we don't know how to convert a value. TypeParameterError: If we can't find a substitution for a type parameter.

def _copy_type_parameters(self, old_container: abstract.Class, new_container_name: str) -> abstract.BaseValue: (source)

Undocumented

def _create_module(self, ast): (source)

Undocumented

def _create_new_unknown_value(self, action) -> abstract.Unknown: (source)

Undocumented

def _get_literal_value(self, pyval, subst): (source)

Extract and convert the value of a pytd.Literal.

def _load_late_type(self, late_type): (source)

Resolve a late type, possibly by loading a module.

def _load_late_type_module(self, late_type): (source)

Undocumented

def _maybe_load_from_overlay(self, module, member_name): (source)

Undocumented

def _special_constant_to_value(self, name): (source)

Special-case construction of some pytd values.

def _type_to_name(self, t): (source)

Convert a type to its name.

_convert_cache: Dict[Any, Any] = (source)

Undocumented

_resolved_late_types: dict = (source)

Undocumented