class documentation

class TypeAnalyser(SyntheticTypeVisitor[Type], TypeAnalyzerPluginInterface): (source)

View In Hierarchy

Semantic analyzer for types.

Converts unbound types into bound types. This is a no-op for already bound types.

If an incomplete reference is encountered, this does a defer. The caller never needs to defer.

Method __init__ Undocumented
Method anal​_array Undocumented
Method anal​_star​_arg​_type Analyze signature argument type for *args and **kwargs argument.
Method anal​_type Undocumented
Method anal​_type​_guard Undocumented
Method anal​_type​_guard​_arg Undocumented
Method anal​_var​_def Undocumented
Method anal​_var​_defs Undocumented
Method analyze​_callable​_args Find types, kinds, and names of arguments from extended callable syntax.
Method analyze​_callable​_args​_for​_paramspec Construct a 'Callable[P, RET]', where P is ParamSpec, return None if we cannot.
Method analyze​_callable​_type Undocumented
Method analyze​_literal​_param Undocumented
Method analyze​_literal​_type Undocumented
Method analyze​_type Analyze an unbound type using the default mypy logic.
Method analyze​_type​_with​_type​_info Bind unbound type when were able to find target TypeInfo.
Method analyze​_unbound​_type​_without​_type​_info Figure out what an unbound type that doesn't refer to a TypeInfo node means.
Method bind​_function​_type​_variables Find the type variables of the function type and bind them in our tvar_scope
Method cannot​_resolve​_type Undocumented
Method fail Emit an error message at given location.
Method get​_omitted​_any Undocumented
Method infer​_type​_variables Return list of unique type variables referred to in a callable.
Method is​_defined​_type​_var Undocumented
Method named​_type Construct an instance of a builtin type with given name.
Method named​_type​_with​_normalized​_str Does almost the same thing as named_type, except that we immediately unalias builtins.bytes and builtins.unicode to builtins.str as appropriate.
Method note Undocumented
Method try​_analyze​_special​_unbound​_type Bind special type that is recognized through magic name such as 'typing.Any'.
Method tuple​_type Undocumented
Method tvar​_scope​_frame Undocumented
Method visit​_any Undocumented
Method visit​_callable​_argument Undocumented
Method visit​_callable​_type Undocumented
Method visit​_deleted​_type Undocumented
Method visit​_ellipsis​_type Undocumented
Method visit​_erased​_type Undocumented
Method visit​_instance Undocumented
Method visit​_literal​_type Undocumented
Method visit​_none​_type Undocumented
Method visit​_overloaded Undocumented
Method visit​_param​_spec Undocumented
Method visit​_partial​_type Undocumented
Method visit​_placeholder​_type Undocumented
Method visit​_raw​_expression​_type Undocumented
Method visit​_star​_type Undocumented
Method visit​_tuple​_type Undocumented
Method visit​_type​_alias​_type Undocumented
Method visit​_type​_list Undocumented
Method visit​_type​_type Undocumented
Method visit​_type​_var Undocumented
Method visit​_typeddict​_type Undocumented
Method visit​_unbound​_type Undocumented
Method visit​_unbound​_type​_nonoptional Undocumented
Method visit​_uninhabited​_type Undocumented
Method visit​_union​_type Undocumented
Class Variable global​_scope Undocumented
Class Variable in​_dynamic​_func Undocumented
Instance Variable aliases​_used Undocumented
Instance Variable allow​_new​_syntax Undocumented
Instance Variable allow​_placeholder Undocumented
Instance Variable allow​_required Undocumented
Instance Variable allow​_tuple​_literal Undocumented
Instance Variable allow​_unbound​_tvars Undocumented
Instance Variable api Undocumented
Instance Variable defining​_alias Undocumented
Instance Variable fail​_func Undocumented
Instance Variable is​_typeshed​_stub Undocumented
Instance Variable lookup​_fqn​_func Undocumented
Instance Variable lookup​_qualified Undocumented
Instance Variable nesting​_level Undocumented
Instance Variable note​_func Undocumented
Instance Variable options Undocumented
Instance Variable plugin Undocumented
Instance Variable report​_invalid​_types Undocumented
Instance Variable tvar​_scope Undocumented
def __init__(self, api, tvar_scope, plugin, options, is_typeshed_stub, *, defining_alias=False, allow_tuple_literal=False, allow_new_syntax=False, allow_unbound_tvars=False, allow_placeholder=False, allow_required=False, report_invalid_types=True): (source)

Undocumented

Parameters
api:SemanticAnalyzerCoreInterfaceUndocumented
tvar​_scope:TypeVarLikeScopeUndocumented
plugin:PluginUndocumented
options:OptionsUndocumented
is​_typeshed​_stub:boolUndocumented
defining​_alias:boolUndocumented
allow​_tuple​_literal:boolUndocumented
allow​_new​_syntax:boolUndocumented
allow​_unbound​_tvars:boolUndocumented
allow​_placeholder:boolUndocumented
allow​_required:boolUndocumented
report​_invalid​_types:boolUndocumented
def anal_array(self, a, nested=True, *, allow_param_spec=False): (source)

Undocumented

Parameters
a:Iterable[Type]Undocumented
nested:boolUndocumented
allow​_param​_spec:boolUndocumented
Returns
List[Type]Undocumented
def anal_star_arg_type(self, t, kind, nested): (source)
Analyze signature argument type for *args and **kwargs argument.
Parameters
t:TypeUndocumented
kind:ArgKindUndocumented
nested:boolUndocumented
Returns
TypeUndocumented
def anal_type(self, t, nested=True, *, allow_param_spec=False): (source)

Undocumented

Parameters
t:TypeUndocumented
nested:boolUndocumented
allow​_param​_spec:boolUndocumented
Returns
TypeUndocumented
def anal_type_guard(self, t): (source)

Undocumented

Parameters
t:TypeUndocumented
Returns
Optional[Type]Undocumented
def anal_type_guard_arg(self, t, fullname): (source)

Undocumented

Parameters
t:UnboundTypeUndocumented
fullname:strUndocumented
Returns
Optional[Type]Undocumented
def anal_var_def(self, var_def): (source)

Undocumented

Parameters
var​_def:TypeVarLikeTypeUndocumented
Returns
TypeVarLikeTypeUndocumented
def anal_var_defs(self, var_defs): (source)

Undocumented

Parameters
var​_defs:Sequence[TypeVarLikeType]Undocumented
Returns
List[TypeVarLikeType]Undocumented
def analyze_callable_args(self, arglist): (source)
Find types, kinds, and names of arguments from extended callable syntax.
Parameters
arglist:TypeListUndocumented
Returns
Optional[Tuple[List[Type], List[ArgKind], List[Optional[str]]]]Undocumented
def analyze_callable_args_for_paramspec(self, callable_args, ret_type, fallback): (source)
Construct a 'Callable[P, RET]', where P is ParamSpec, return None if we cannot.
Parameters
callable​_args:TypeUndocumented
ret​_type:TypeUndocumented
fallback:InstanceUndocumented
Returns
Optional[CallableType]Undocumented
def analyze_callable_type(self, t): (source)

Undocumented

Parameters
t:UnboundTypeUndocumented
Returns
TypeUndocumented
def analyze_literal_param(self, idx, arg, ctx): (source)

Undocumented

Parameters
idx:intUndocumented
arg:TypeUndocumented
ctx:ContextUndocumented
Returns
Optional[List[Type]]Undocumented
def analyze_literal_type(self, t): (source)

Undocumented

Parameters
t:UnboundTypeUndocumented
Returns
TypeUndocumented
def analyze_type(self, t): (source)
Analyze an unbound type using the default mypy logic.
Parameters
t:TypeUndocumented
Returns
TypeUndocumented
def analyze_type_with_type_info(self, info, args, ctx): (source)

Bind unbound type when were able to find target TypeInfo.

This handles simple cases like 'int', 'modname.UserClass[str]', etc.

Parameters
info:TypeInfoUndocumented
args:Sequence[Type]Undocumented
ctx:ContextUndocumented
Returns
TypeUndocumented
def analyze_unbound_type_without_type_info(self, t, sym, defining_literal): (source)

Figure out what an unbound type that doesn't refer to a TypeInfo node means.

This is something unusual. We try our best to find out what it is.

Parameters
t:UnboundTypeUndocumented
sym:SymbolTableNodeUndocumented
defining​_literal:boolUndocumented
Returns
TypeUndocumented
def bind_function_type_variables(self, fun_type, defn): (source)
Find the type variables of the function type and bind them in our tvar_scope
Parameters
fun​_type:CallableTypeUndocumented
defn:ContextUndocumented
Returns
Sequence[TypeVarLikeType]Undocumented
def cannot_resolve_type(self, t): (source)

Undocumented

Parameters
t:UnboundTypeUndocumented
def fail(self, msg, ctx, *, code=None): (source)
Emit an error message at given location.
Parameters
msg:strUndocumented
ctx:ContextUndocumented
code:Optional[ErrorCode]Undocumented
def get_omitted_any(self, typ, fullname=None): (source)

Undocumented

Parameters
typ:TypeUndocumented
fullname:Optional[str]Undocumented
Returns
AnyTypeUndocumented
def infer_type_variables(self, type): (source)
Return list of unique type variables referred to in a callable.
Parameters
type:CallableTypeUndocumented
Returns
List[Tuple[str, TypeVarLikeExpr]]Undocumented
def is_defined_type_var(self, tvar, context): (source)

Undocumented

Parameters
tvar:strUndocumented
context:ContextUndocumented
Returns
boolUndocumented
def named_type(self, fully_qualified_name, args=None, line=-1, column=-1): (source)
Construct an instance of a builtin type with given name.
Parameters
fully​_qualified​_name:strUndocumented
args:Optional[List[Type]]Undocumented
line:intUndocumented
column:intUndocumented
Returns
InstanceUndocumented
def named_type_with_normalized_str(self, fully_qualified_name): (source)
Does almost the same thing as named_type, except that we immediately unalias builtins.bytes and builtins.unicode to builtins.str as appropriate.
Parameters
fully​_qualified​_name:strUndocumented
Returns
InstanceUndocumented
def note(self, msg, ctx, *, code=None): (source)

Undocumented

Parameters
msg:strUndocumented
ctx:ContextUndocumented
code:Optional[ErrorCode]Undocumented
def try_analyze_special_unbound_type(self, t, fullname): (source)

Bind special type that is recognized through magic name such as 'typing.Any'.

Return the bound type if successful, and return None if the type is a normal type.

Parameters
t:UnboundTypeUndocumented
fullname:strUndocumented
Returns
Optional[Type]Undocumented
def tuple_type(self, items): (source)

Undocumented

Parameters
items:List[Type]Undocumented
Returns
TupleTypeUndocumented
@contextmanager
def tvar_scope_frame(self): (source)

Undocumented

Returns
Iterator[None]Undocumented
def visit_any(self, t): (source)

Undocumented

Parameters
t:AnyTypeUndocumented
Returns
TypeUndocumented
def visit_callable_argument(self, t): (source)

Undocumented

Parameters
t:CallableArgumentUndocumented
Returns
TypeUndocumented
def visit_callable_type(self, t, nested=True): (source)

Undocumented

Parameters
t:CallableTypeUndocumented
nested:boolUndocumented
Returns
TypeUndocumented
def visit_deleted_type(self, t): (source)

Undocumented

Parameters
t:DeletedTypeUndocumented
Returns
TypeUndocumented
def visit_ellipsis_type(self, t): (source)

Undocumented

Parameters
t:EllipsisTypeUndocumented
Returns
TypeUndocumented
def visit_erased_type(self, t): (source)

Undocumented

Parameters
t:ErasedTypeUndocumented
Returns
TypeUndocumented
def visit_instance(self, t): (source)

Undocumented

Parameters
t:InstanceUndocumented
Returns
TypeUndocumented
def visit_literal_type(self, t): (source)

Undocumented

Parameters
t:LiteralTypeUndocumented
Returns
TypeUndocumented
def visit_none_type(self, t): (source)

Undocumented

Parameters
t:NoneTypeUndocumented
Returns
TypeUndocumented
def visit_overloaded(self, t): (source)

Undocumented

Parameters
t:OverloadedUndocumented
Returns
TypeUndocumented
def visit_param_spec(self, t): (source)

Undocumented

Parameters
t:ParamSpecTypeUndocumented
Returns
TypeUndocumented
def visit_partial_type(self, t): (source)

Undocumented

Parameters
t:PartialTypeUndocumented
Returns
TypeUndocumented
def visit_placeholder_type(self, t): (source)

Undocumented

Parameters
t:PlaceholderTypeUndocumented
Returns
TypeUndocumented
def visit_raw_expression_type(self, t): (source)

Undocumented

Parameters
t:RawExpressionTypeUndocumented
Returns
TypeUndocumented
def visit_star_type(self, t): (source)

Undocumented

Parameters
t:StarTypeUndocumented
Returns
TypeUndocumented
def visit_tuple_type(self, t): (source)

Undocumented

Parameters
t:TupleTypeUndocumented
Returns
TypeUndocumented
def visit_type_alias_type(self, t): (source)

Undocumented

Parameters
t:TypeAliasTypeUndocumented
Returns
TypeUndocumented
def visit_type_list(self, t): (source)

Undocumented

Parameters
t:TypeListUndocumented
Returns
TypeUndocumented
def visit_type_type(self, t): (source)

Undocumented

Parameters
t:TypeTypeUndocumented
Returns
TypeUndocumented
def visit_type_var(self, t): (source)

Undocumented

Parameters
t:TypeVarTypeUndocumented
Returns
TypeUndocumented
def visit_typeddict_type(self, t): (source)

Undocumented

Parameters
t:TypedDictTypeUndocumented
Returns
TypeUndocumented
def visit_unbound_type(self, t, defining_literal=False): (source)

Undocumented

Parameters
t:UnboundTypeUndocumented
defining​_literal:boolUndocumented
Returns
TypeUndocumented
def visit_unbound_type_nonoptional(self, t, defining_literal): (source)

Undocumented

Parameters
t:UnboundTypeUndocumented
defining​_literal:boolUndocumented
Returns
TypeUndocumented
def visit_uninhabited_type(self, t): (source)

Undocumented

Parameters
t:UninhabitedTypeUndocumented
Returns
TypeUndocumented
def visit_union_type(self, t): (source)

Undocumented

Parameters
t:UnionTypeUndocumented
Returns
TypeUndocumented
global_scope: bool = (source)

Undocumented

in_dynamic_func: bool = (source)

Undocumented

aliases_used: Set[str] = (source)

Undocumented

allow_new_syntax = (source)

Undocumented

allow_placeholder = (source)

Undocumented

allow_required = (source)

Undocumented

allow_tuple_literal = (source)

Undocumented

allow_unbound_tvars = (source)

Undocumented

Undocumented

defining_alias = (source)

Undocumented

fail_func = (source)

Undocumented

is_typeshed_stub = (source)

Undocumented

lookup_fqn_func = (source)

Undocumented

lookup_qualified = (source)

Undocumented

nesting_level: int = (source)

Undocumented

note_func = (source)

Undocumented

plugin = (source)

Undocumented

report_invalid_types = (source)

Undocumented

tvar_scope = (source)

Undocumented