class AnnotationUtils(utils.ContextWeakrefMixin): (source)
Utility class for inline type annotations.
Method | add |
Add scope for type parameters. |
Method | apply |
If there is an annotation for the op, return its value. |
Method | convert |
Convert a (name, raw_annot) list to a {name: annotation} dict. |
Method | convert |
Convert a name -> raw_annot dict to annotations. |
Method | convert |
Convert raw annotations to a {name: annotation} dict. |
Method | convert |
Undocumented |
Method | deformalize |
Undocumented |
Method | eval |
Evaluate annotation for multiple arguments (from a type comment). |
Method | extract |
Extracts an annotation from var and instantiates it. |
Method | extract |
Returns an annotation extracted from 'var'. |
Method | get |
Gets all TypeParameter names that appear in a Callable in 'val'. |
Method | get |
Undocumented |
Method | get |
Returns all the TypeParameter instances that appear in the annotation. |
Method | init |
Undocumented |
Method | remove |
Replace unresolved late annotations with unsolvables. |
Method | sub |
Apply type parameter substitutions to a dictionary of annotations. |
Method | sub |
Apply type parameter substitutions to a dictionary of annotations. |
Method | sub |
Undocumented |
Method | _do |
Apply type parameter substitutions to an annotation. |
Method | _eval |
Evaluate an expression as a tuple. |
Method | _get |
Helper for sub_one_annotation. |
Method | _process |
Change annotation / record errors where required. |
Inherited from ContextWeakrefMixin
:
Method | __init__ |
Undocumented |
Class Variable | __slots__ |
Undocumented |
Instance Variable | ctx |
Undocumented |
Property | ctx |
Undocumented |
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.
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.
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.
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.
cfg.CFGNode
, annot: abstract.TypeParameter
, substs: Sequence[ Dict[ str, cfg.Variable]]
, instantiate_unbound: bool
) -> abstract.BaseValue
:
(source)
¶
Helper for sub_one_annotation.
cfg.CFGNode
, annotation: abstract.BaseValue
, name: Optional[ str]
, stack: Tuple[ state.FrameType, ...]
) -> Optional[ abstract.BaseValue]
:
(source)
¶
Change annotation / record errors where required.