class documentation

Utility class for inline type annotations.

Method add_scope Add scope for type parameters.
Method apply_annotation If there is an annotation for the op, return its value.
Method convert_annotations_list Convert a (name, raw_annot) list to a {name: annotation} dict.
Method convert_class_annotations Convert a name -> raw_annot dict to annotations.
Method convert_function_annotations Convert raw annotations to a {name: annotation} dict.
Method convert_function_type_annotation Undocumented
Method deformalize Undocumented
Method eval_multi_arg_annotation Evaluate annotation for multiple arguments (from a type comment).
Method extract_and_init_annotation Extracts an annotation from var and instantiates it.
Method extract_annotation Returns an annotation extracted from 'var'.
Method get_callable_type_parameter_names Gets all TypeParameter names that appear in a Callable in 'val'.
Method get_late_annotations Undocumented
Method get_type_parameters Returns all the TypeParameter instances that appear in the annotation.
Method init_annotation Undocumented
Method remove_late_annotations Replace unresolved late annotations with unsolvables.
Method sub_annotations Apply type parameter substitutions to a dictionary of annotations.
Method sub_annotations_for_parameterized_class Apply type parameter substitutions to a dictionary of annotations.
Method sub_one_annotation Undocumented
Method _do_sub_one_annotation Apply type parameter substitutions to an annotation.
Method _eval_expr_as_tuple Evaluate an expression as a tuple.
Method _get_type_parameter_subst Helper for sub_one_annotation.
Method _process_one_annotation Change annotation / record errors where required.

Inherited from ContextWeakrefMixin:

Method __init__ Undocumented
Class Variable __slots__ Undocumented
Instance Variable ctx_weakref Undocumented
Property ctx Undocumented
def add_scope(self, annot, types, module, seen=None): (source)

Add scope for type parameters. In original type class, all type parameters that should be added a scope will be replaced with a new copy. Args: annot: The type class. types: A type name list that should be added a scope. module: Module name. seen: Already seen types. Returns: The type with fresh type parameters that have been added the scope.

def apply_annotation(self, node, op, name, value): (source)

If there is an annotation for the op, return its value.

def convert_annotations_list(self, node, annotations_list): (source)

Convert a (name, raw_annot) list to a {name: annotation} dict.

def convert_class_annotations(self, node, raw_annotations): (source)

Convert a name -> raw_annot dict to annotations.

def convert_function_annotations(self, node, raw_annotations): (source)

Convert raw annotations to a {name: annotation} dict.

def convert_function_type_annotation(self, name, typ): (source)

Undocumented

def deformalize(self, value): (source)

Undocumented

def eval_multi_arg_annotation(self, node, func, annot, stack): (source)

Evaluate annotation for multiple arguments (from a type comment).

def extract_and_init_annotation(self, node, name, var): (source)

Extracts an annotation from var and instantiates it.

def extract_annotation(self, node, var, name, stack, allowed_type_params: Optional[AbstractSet[str]] = None): (source)

Returns an annotation extracted from 'var'. Args: node: The current node. var: The variable to extract from. name: The annotated name. stack: The frame stack. allowed_type_params: Type parameters that are allowed to appear in the annotation. 'None' means all are allowed. If non-None, the result of calling get_callable_type_parameter_names on the extracted annotation is also added to the allowed set.

def get_callable_type_parameter_names(self, val: abstract.BaseValue): (source)

Gets all TypeParameter names that appear in a Callable in 'val'.

def get_late_annotations(self, annot): (source)

Undocumented

def get_type_parameters(self, annot, seen=None): (source)

Returns all the TypeParameter instances that appear in the annotation. Note that if you just need to know whether or not the annotation contains type parameters, you can check its `.formal` attribute. Args: annot: An annotation. seen: A seen set.

def init_annotation(self, node, name, annot, container=None, extra_key=None): (source)

Undocumented

def remove_late_annotations(self, annot, seen=None): (source)

Replace unresolved late annotations with unsolvables.

def sub_annotations(self, node, annotations, substs, instantiate_unbound): (source)

Apply type parameter substitutions to a dictionary of annotations.

def sub_annotations_for_parameterized_class(self, cls: abstract.ParameterizedClass, annotations: Dict[str, abstract.BaseValue]) -> Dict[str, abstract.BaseValue]: (source)

Apply type parameter substitutions to a dictionary of annotations. Args: cls: ParameterizedClass that defines type parameter substitutions. annotations: A dictionary of annotations to which type parameter substition should be applied. Returns: Annotations with type parameters substituted.

def sub_one_annotation(self, node, annot, substs, instantiate_unbound=True): (source)

Undocumented

def _do_sub_one_annotation(self, node, annot, get_type_parameter_subst_fn): (source)

Apply type parameter substitutions to an annotation.

def _eval_expr_as_tuple(self, node, expr, stack): (source)

Evaluate an expression as a tuple.

def _get_type_parameter_subst(self, node: cfg.CFGNode, annot: abstract.TypeParameter, substs: Sequence[Dict[str, cfg.Variable]], instantiate_unbound: bool) -> abstract.BaseValue: (source)

Helper for sub_one_annotation.

def _process_one_annotation(self, node: cfg.CFGNode, annotation: abstract.BaseValue, name: Optional[str], stack: Tuple[state.FrameType, ...]) -> Optional[abstract.BaseValue]: (source)

Change annotation / record errors where required.