class documentation

An abstract value representing a user-defined function. Attributes: name: Function name. Might just be something like "<lambda>". code: A code object. closure: Tuple of cells (cfg.Variable) containing the free variables this closure binds to. ctx: context.Context instance.

Class Method make Get an InterpreterFunction.
Method __init__ Initialize a SimpleValue.
Method argcount Returns the minimum number of arguments needed for a call.
Method call Call this abstract value with the given arguments.
Method get_call_combinations Get this function's call records.
Method get_first_opcode Undocumented
Method get_kwonly_names Undocumented
Method get_nondefault_params Undocumented
Method get_parameters Undocumented
Method get_positional_names Undocumented
Method has_empty_body Undocumented
Method has_kwargs Return True if this is a function and has a **kwargs parameter.
Method has_varargs Return True if this is a function and has a *args parameter.
Method is_coroutine Undocumented
Method iter_signature_functions Loop through signatures, setting each as the primary one in turn.
Method match_args Check whether the given arguments can match the function signature.
Method property_get Bind this value to the given self or cls.
Method record_calls Turn on recording of function calls. Used by analyze.py.
Method signature_functions Get the functions that describe this function's signature.
Instance Variable bound_class Undocumented
Instance Variable closure Undocumented
Instance Variable code Undocumented
Instance Variable def_opcode Undocumented
Instance Variable defaults Undocumented
Instance Variable doc Undocumented
Instance Variable f_globals Undocumented
Instance Variable f_locals Undocumented
Instance Variable has_overloads Undocumented
Instance Variable is_class_builder Undocumented
Instance Variable is_classmethod Undocumented
Instance Variable is_overload Undocumented
Instance Variable kw_defaults Undocumented
Instance Variable last_frame Undocumented
Instance Variable nonstararg_count Undocumented
Instance Variable posonlyarg_count Undocumented
Method _build_signature Build a function.Signature object representing this function.
Method _check_signature Validate function signature.
Method _find_matching_sig Undocumented
Method _fix_args_for_unannotated_contextmanager_exit Adjust argument types for a contextmanager's __exit__ method.
Method _handle_paramspec Undocumented
Method _hash_call Undocumented
Method _inner_cls_check Check if the function and its nested class use same type parameter.
Method _paramspec_signature Undocumented
Method _set_callself_maybe_missing_members Undocumented
Method _update_signature_scope Undocumented
Class Variable _function_cache Undocumented
Instance Variable _call_cache Undocumented
Instance Variable _call_records Undocumented
Instance Variable _overloads Undocumented
Instance Variable _store_call_records Undocumented

Inherited from SignedFunction:

Method match_and_map_args Calls match_args() and _map_args().
Method set_function_defaults Attempts to set default arguments of a function.
Method set_self_annot Set the annotation for `self` in a class.
Instance Variable signature Undocumented
Method _check_paramspec_args Undocumented
Method _map_args Map call args to function args.
Method _match_args_sequentially Undocumented
Method _mutations_generator Undocumented
Instance Variable _has_self_annot Undocumented

Inherited from Function (via SignedFunction):

Method __repr__ Undocumented
Instance Variable cls Undocumented
Instance Variable is_abstract Undocumented
Instance Variable is_attribute_of_class Undocumented
Instance Variable is_method Undocumented
Method _extract_defaults Extracts defaults from a Variable, used by set_function_defaults.
Method _get_cell_variable_name Get the python variable name of a pytype Variable.

Inherited from SimpleValue (via SignedFunction, Function):

Method cls.setter Undocumented
Method get_fullhash Undocumented
Method get_instance_type_parameter Get a cfg.Variable of the instance's values for the type parameter.
Method get_type_key Build a key from the information used to perform type matching.
Method has_instance_type_parameter Check if the key is in `instance_type_parameters`.
Method instantiate Create an instance of self.
Method maybe_missing_members.setter Undocumented
Method merge_instance_type_parameter Set the value of a type parameter.
Method set_class Set the __class__ of an instance, for code that does "x.__class__ = y.
Method update_caches Undocumented
Instance Variable members Undocumented
Property instance_type_parameters Undocumented
Property maybe_missing_members Undocumented
Method _call_helper Undocumented
Method _get_changestamps Undocumented
Method _get_class Undocumented
Method _unique_parameters Get unique parameter subtypes as variables.
Instance Variable _cached_changestamps Undocumented
Instance Variable _cls Undocumented
Instance Variable _fullhash Undocumented
Instance Variable _instance_type_parameters Undocumented
Instance Variable _maybe_missing_members Undocumented
Instance Variable _type_key Undocumented

Inherited from BaseValue (via SignedFunction, Function, SimpleValue):

Method compute_mro Undocumented
Method default_mro Undocumented
Method get_default_fullhash Undocumented
Method get_default_type_key Gets a default type key. See get_type_key.
Method get_formal_type_parameter Get the class's type for the type parameter.
Method get_instance_type Get the type an instance of us would have.
Method get_own_new Get this value's __new__ method, if it isn't object.__new__.
Method get_special_attribute Fetch a special attribute (e.g., __get__, __iter__).
Method init_subclass Allow metaprogramming via __init_subclass__.
Method is_late_annotation Undocumented
Method module.setter Undocumented
Method official_name.setter Undocumented
Method register_instance Treating self as a class definition, register an instance of it.
Method should_replace_self_annot Undocumented
Method to_annotation_container Undocumented
Method to_binding Undocumented
Method to_pytd_def Get a PyTD definition for this object.
Method to_type Get a PyTD type representing this object, as seen at a node.
Method to_variable Build a variable out of this abstract value.
Method unique_parameter_values Get unique parameter subtypes as bindings.
Method update_official_name Update the official name.
Class Variable formal Undocumented
Instance Variable final Undocumented
Instance Variable from_annotation Undocumented
Instance Variable is_concrete Undocumented
Instance Variable is_decorated Undocumented
Instance Variable mro Undocumented
Instance Variable name Undocumented
Instance Variable slots Undocumented
Property all_template_names Undocumented
Property full_name Undocumented
Property module Undocumented
Property official_name Undocumented
Property template Undocumented
Instance Variable _all_template_names Undocumented
Instance Variable _instance Undocumented
Instance Variable _module Undocumented
Instance Variable _official_name Undocumented
Instance Variable _template Undocumented

Inherited from ContextWeakrefMixin (via SignedFunction, Function, SimpleValue, BaseValue):

Class Variable __slots__ Undocumented
Instance Variable ctx_weakref Undocumented
Property ctx Undocumented
@classmethod
def make(cls, name, *, def_opcode, code, f_locals, f_globals, defaults, kw_defaults, closure, annotations, ctx): (source)

Get an InterpreterFunction. Things like anonymous functions and generator expressions are created every time the corresponding code executes. Caching them makes it easier to detect when the environment hasn't changed and a function call can be optimized away. Arguments: name: Function name. def_opcode: The opcode for the def statement code: A code object. f_locals: The locals used for name resolution. f_globals: The globals used for name resolution. defaults: Default arguments. kw_defaults: Default arguments for kwonly parameters. closure: The free variables this closure binds to. annotations: Function annotations. Dict of name -> BaseValue. ctx: context.Context instance. Returns: An InterpreterFunction.

def __init__(self, name, def_opcode, code, f_locals, f_globals, defaults, kw_defaults, closure, annotations, overloads, ctx): (source)

Initialize a SimpleValue. Args: name: Name of this value. For debugging and error reporting. ctx: The abstract context.

def argcount(self, _): (source)

Returns the minimum number of arguments needed for a call.

def call(self, node, func, args, alias_map=None, new_locals=False, frame_substs=()): (source)

Call this abstract value with the given arguments. The posargs and namedargs arguments may be modified by this function. Args: node: The CFGNode calling this function func: The cfg.Binding containing this function. args: Arguments for the call. alias_map: A datatypes.UnionFind, which stores all the type renaming information, mapping of type parameter name to its representative. Returns: A tuple (cfg.Node, cfg.Variable). The CFGNode corresponds to the function's "return" statement(s). Raises: function.FailedFunctionCall Make the call as required by this specific kind of atomic value, and make sure to annotate the results correctly with the origins (val and also other values appearing in the arguments).

def get_call_combinations(self, node): (source)

Get this function's call records.

def get_kwonly_names(self): (source)

Undocumented

def get_parameters(self): (source)

Undocumented

def get_positional_names(self): (source)

Undocumented

def has_empty_body(self): (source)

Undocumented

def has_kwargs(self): (source)

Return True if this is a function and has a **kwargs parameter.

def has_varargs(self): (source)

Return True if this is a function and has a *args parameter.

def is_coroutine(self): (source)

Undocumented

def iter_signature_functions(self): (source)

Loop through signatures, setting each as the primary one in turn.

def match_args(self, node, args, alias_map=None, match_all_views=False): (source)

Check whether the given arguments can match the function signature.

def property_get(self, callself, is_class=False): (source)

Bind this value to the given self or cls. This function is similar to __get__ except at the abstract level. This does not trigger any code execution inside the VM. See __get__ for more details. Args: callself: The Variable that should be passed as self or cls when the call is made. We only need one of self or cls, so having them share a parameter prevents accidentally passing in both. is_class: Whether callself is self or cls. Should be cls only when we want to directly pass in a class to bind a class method to, rather than passing in an instance and calling get_class(). Returns: Another abstract value that should be returned in place of this one. The default implementation returns self, so this can always be called safely.

Turn on recording of function calls. Used by analyze.py.

def signature_functions(self): (source)

Get the functions that describe this function's signature.

Undocumented

Undocumented

def_opcode = (source)

Undocumented

defaults = (source)

Undocumented

Undocumented

f_globals = (source)

Undocumented

f_locals = (source)

Undocumented

has_overloads = (source)

Undocumented

is_class_builder: bool = (source)

Undocumented

is_overload: bool = (source)

Undocumented

kw_defaults = (source)

Undocumented

last_frame = (source)

Undocumented

nonstararg_count = (source)

Undocumented

posonlyarg_count = (source)

Undocumented

def _build_signature(self, name, annotations): (source)

Build a function.Signature object representing this function.

def _check_signature(self): (source)

Validate function signature.

def _find_matching_sig(self, node, args, alias_map): (source)

Undocumented

def _fix_args_for_unannotated_contextmanager_exit(self, node, func, args): (source)

Adjust argument types for a contextmanager's __exit__ method.

def _handle_paramspec(self, sig, annotations, substs, callargs): (source)

Undocumented

def _hash_call(self, callargs, frame): (source)

Undocumented

def _inner_cls_check(self, last_frame): (source)

Check if the function and its nested class use same type parameter.

def _paramspec_signature(self, callable_type, substs): (source)

Undocumented

def _set_callself_maybe_missing_members(self): (source)

Undocumented

def _update_signature_scope(self): (source)

Undocumented

_function_cache: dict = (source)

Undocumented

_call_cache: dict = (source)

Undocumented

_call_records: list = (source)

Undocumented

_overloads = (source)

Undocumented

_store_call_records = (source)

Undocumented