Utilities for abstract.py.
Class |
|
Wrapper, used for marking things that we want to convert to an instance. |
Class |
|
Specially mark return values, to handle NoReturn properly. |
Class |
|
Undocumented |
Class |
|
Undocumented |
Class |
|
A possibly annotated local variable. |
Exception |
|
Undocumented |
Exception |
|
Used to signal an errorlog error during type name evaluation. |
Exception |
|
The error for user-defined generic types. |
Exception |
|
Signal an error when trying to lazily load a submodule. |
Function | apply |
Apply mutations yielded from a get_mutations function. |
Function | build |
Build a typing.Generic template from a sequence of type parameters. |
Function | check |
Check if any of the classes are in the target's MRO. |
Function | combine |
Combines the two collections of type parameter substitutions. |
Function | equivalent |
Whether binding.data is equivalent to cls, modulo parameterization. |
Function | eval |
Evaluate an expression with the given node and globals. |
Function | expand |
Expands any TypeParameterInstance values in `bindings`. |
Function | flatten |
Flatten the contents of value into classes. |
Function | full |
Compute complete type parameter name with scope. |
Function | get |
Get __annotations__ from a members map. |
Function | get |
Get the concrete atomic Python value stored in this variable. |
Function | get |
Get the atomic value stored in this variable. |
Function | get |
Hash a dictionary. |
Function | get |
Gets the generic type of an abstract value. |
Function | get |
Get bases for MRO computation. |
Function | get |
Get values for type_params from val's type parameters. |
Function | get |
Undocumented |
Function | get |
Get all possible views of the given variables at a particular node. |
Function | is |
Returns whether 'value' is a callable. |
Function | is |
Undocumented |
Function | is |
Undocumented |
Function | is |
Undocumented |
Function | is |
Undocumented |
Function | is |
True if val is a non-concrete instance of typing.Iterable. |
Function | is |
Undocumented |
Function | is |
Wehther binding.data is a subclass of cls, modulo parameterization. |
Function | is |
True if all bindings of var are indefinite sequences. |
Function | is |
Undocumented |
Function | match |
Undocumented |
Function | match |
Undocumented |
Function | match |
Unpack the type parameter from ContainerType[T]. |
Function | maybe |
Returns a tuple of Variables. |
Function | maybe |
Undocumented |
Function | merged |
Undocumented |
Function | parse |
Parse type parameters from base class. |
Function | show |
Pretty-print a value if it is a constant. |
Function | simplify |
Deduplicates identical data in `var`. |
Function | unwrap |
Unwrap Final[T] -> T. |
Function | unwrap |
Undocumented |
Function | update |
Update a {str: Variable} dict by merging bindings. |
Function | with |
Undocumented |
Constant | ARGS |
Undocumented |
Constant | CLASS |
Undocumented |
Constant | DUMMY |
Undocumented |
Constant | DYNAMIC |
Undocumented |
Constant | K |
Undocumented |
Constant | RET |
Undocumented |
Constant | T |
Undocumented |
Constant | T2 |
Undocumented |
Constant | TOP |
Undocumented |
Constant | V |
Undocumented |
Variable | log |
Undocumented |
Class | _ |
Undocumented |
Function | _isinstance |
Do an isinstance() call for a class defined in pytype.abstract. |
Function | _make |
Make an instance of cls_name with the given arguments. |
Function | _merge |
Merge two types. |
Type Alias | _ |
Undocumented |
Sequence[ _BaseValueType]
, base_type: _BaseValueType
) -> Tuple[ Sequence[ str], Sequence[ _TypeParamType]]
:
(source)
¶
Build a typing.Generic template from a sequence of type parameters.
Check if any of the classes are in the target's MRO. Args: ctx: The abstract context. target: A BaseValue whose MRO will be checked. class_spec: A Class or PythonConstant tuple of classes (i.e. the second argument to isinstance or issubclass). Returns: True if any class in classes is found in the target's MRO, False if no match is found and None if it's ambiguous.
Optional[ Collection[ Dict[ str, cfg.Variable]]]
, substs2: Optional[ Collection[ Dict[ str, cfg.Variable]]]
) -> Collection[ Dict[ str, cfg.Variable]]
:
(source)
¶
Combines the two collections of type parameter substitutions.
Flatten the contents of value into classes. If value is a Class, it is appended to classes. If value is a PythonConstant of type tuple, then each element of the tuple that has a single binding is also flattened. Any other type of value, or tuple elements that have multiple bindings are ignored. Args: value: An abstract value. classes: A list to be modified. Returns: True iff a value was ignored during flattening.
Compute complete type parameter name with scope. Args: val: The object with type parameters. name: The short type parameter name (e.g., T). Returns: The full type parameter name (e.g., List.T).
Get __annotations__ from a members map. Returns None rather than {} if the dict does not exist so that callers always have a reference to the actual dictionary, and can mutate it if needed. Args: members: A dict of member name to variable Returns: members['__annotations__'] unpacked as a python dict, or None
Get the concrete atomic Python value stored in this variable. This is used for things that are stored in cfg.Variable, but we need the actual data in order to proceed. E.g. function / class definitions. Args: variable: A cfg.Variable. It can only have one possible value. constant_type: Optionally, the required type of the constant. Returns: A Python constant. (Typically, a string, a tuple, or a code object.) Raises: ConversionError: If the value in this Variable is purely abstract, i.e. doesn't store a Python value, or if it has more than one possible value.
Dict[ str, cfg.Variable]
, *, names: Optional[ Set[ str]]
= None, seen: Optional[ Set[ _BaseValueType]]
= None) -> Tuple[ Any, ...]
:
(source)
¶
Hash a dictionary. This contains the keys and the full hashes of the data in the values. Arguments: vardict: A dictionary mapping str to Variable. names: If this is non-None, the snapshot will include only those dictionary entries whose keys appear in names. seen: Optionally, a set of seen values for recursion detection. Returns: A hashable tuple of the dictionary.
Gets the generic type of an abstract value. Args: val: The abstract value. Returns: The type of the value, with concrete type parameters replaced by TypeVars. For example, the generic type of `[0]` is `List[T]`.
_BaseValueType
, type_params: Iterable[ _TypeParamType]
) -> Mapping[ str, cfg.Variable]
:
(source)
¶
Get values for type_params from val's type parameters.
cfg.Variable
, seen: Optional[ Set[ _BaseValueType]]
= None) -> Tuple[ Any, ...]
:
(source)
¶
Undocumented
Get all possible views of the given variables at a particular node. For performance reasons, this method uses node.CanHaveCombination for filtering. For a more precise check, you can call node.HasCombination(list(view.values())). Do so judiciously, as the latter method can be very slow. This function can be used either as a regular generator or in an optimized way to yield only functionally unique views: views = get_views(...) skip_future = None while True: try: view = views.send(skip_future) except StopIteration: break ... The caller should set `skip_future` to True when it is safe to skip equivalent future views and False otherwise. Args: variables: The variables. node: The node. Yields: A datatypes.AcessTrackingDict mapping variables to bindings.
Parse type parameters from base class. Args: base: base class. prefix: the full name of subclass of base class. formal_type_parameters: the mapping of type parameter name to its type. container: An abstract value whose class template is used when prefix=None to decide how to handle type parameters that are aliased to other type parameters. Values that are in the class template are kept, while all others are ignored. Raises: GenericTypeError: If the lazy types of type parameter don't match
Pretty-print a value if it is a constant. Recurses into a constant, printing the underlying Python value for constants and just using "..." for everything else (e.g., Variables). This is useful for generating clear error messages that show the exact values related to an error while preventing implementation details from leaking into the message. Args: val: an abstract value. Returns: A string of the pretty-printed constant.
Undocumented
Value |
|
Undocumented
Value |
|
Do an isinstance() call for a class defined in pytype.abstract. Args: obj: An instance. name_or_names: A name or tuple of names of classes in pytype.abstract. Returns: Whether obj is an instance of name_or_names.
Merge two types. Rules: Type `Any` can match any type, we will return the other type if one of them is `Any`. Return the sub-class if the types have inheritance relationship. Args: t0: The first type. t1: The second type. name: Type parameter name. cls: The class_mixin.Class on which any error should be reported. Returns: A type. Raises: GenericTypeError: if the types don't match.