module documentation
(source)

Semantic analysis of types
Class ​Collect​All​Inner​Types​Query Undocumented
Class ​Collect​Any​Types​Query Undocumented
Class ​Has​Any​From​Unimported​Type Undocumented
Class ​Has​Explicit​Any Undocumented
Class ​Instance​Fixer Undocumented
Class ​Type​Analyser Semantic analyzer for types.
Class ​Type​Var​Like​Query Find TypeVar and ParamSpec references in an unbound type.
Function analyze​_type​_alias Analyze r.h.s. of a (potential) type alias definition.
Function check​_for​_explicit​_any Undocumented
Function collect​_all​_inner​_types Return all types that t contains
Function collect​_any​_types Return all inner `AnyType`s of type t
Function expand​_type​_alias Expand a (generic) type alias target following the rules outlined in TypeAlias docstring.
Function fix​_instance Fix a malformed instance by replacing all type arguments with Any.
Function fix​_instance​_types Recursively fix all instance types (type argument count) in a given type.
Function flatten​_tvars Undocumented
Function get​_omitted​_any Undocumented
Function has​_any​_from​_unimported​_type Return true if this type is Any because an import was not followed.
Function has​_explicit​_any Whether this type is or type it contains is an Any coming from explicit type annotation
Function make​_optional​_type Return the type corresponding to Optional[t].
Function no​_subscript​_builtin​_alias Undocumented
Function remove​_dups Undocumented
Function set​_any​_tvars Undocumented
Constant ARG​_KINDS​_BY​_CONSTRUCTOR Undocumented
Constant GENERIC​_STUB​_NOT​_AT​_RUNTIME​_TYPES Undocumented
Constant T Undocumented
Constant type​_constructors Undocumented
Variable ​Msg​Callback Undocumented
Variable ​Type​Var​Like​List Undocumented
def analyze_type_alias(node, api, tvar_scope, plugin, options, is_typeshed_stub, allow_new_syntax=False, allow_placeholder=False, in_dynamic_func=False, global_scope=True): (source)

Analyze r.h.s. of a (potential) type alias definition.

If node is valid as a type alias rvalue, return the resulting type and a set of full names of type aliases it depends on (directly or indirectly). Return None otherwise. 'node' must have been semantically analyzed.

Parameters
node:ExpressionUndocumented
api:SemanticAnalyzerCoreInterfaceUndocumented
tvar​_scope:TypeVarLikeScopeUndocumented
plugin:PluginUndocumented
options:OptionsUndocumented
is​_typeshed​_stub:boolUndocumented
allow​_new​_syntax:boolUndocumented
allow​_placeholder:boolUndocumented
in​_dynamic​_func:boolUndocumented
global​_scope:boolUndocumented
Returns
Optional[Tuple[Type, Set[str]]]Undocumented
def check_for_explicit_any(typ, options, is_typeshed_stub, msg, context): (source)

Undocumented

Parameters
typ:Optional[Type]Undocumented
options:OptionsUndocumented
is​_typeshed​_stub:boolUndocumented
msg:MessageBuilderUndocumented
context:ContextUndocumented
def collect_all_inner_types(t): (source)
Return all types that t contains
Parameters
t:TypeUndocumented
Returns
List[Type]Undocumented
def collect_any_types(t): (source)
Return all inner `AnyType`s of type t
Parameters
t:TypeUndocumented
Returns
List[AnyType]Undocumented
def expand_type_alias(node, args, fail, no_args, ctx, *, unexpanded_type=None, disallow_any=False): (source)

Expand a (generic) type alias target following the rules outlined in TypeAlias docstring.

Here:
target: original target type (contains unbound type variables) alias_tvars: type variable names args: types to be substituted in place of type variables fail: error reporter callback no_args: whether original definition used a bare generic A = List ctx: context where expansion happens
Parameters
node:TypeAliasUndocumented
args:List[Type]Undocumented
fail:MsgCallbackUndocumented
no​_args:boolUndocumented
ctx:ContextUndocumented
unexpanded​_type:Optional[Type]Undocumented
disallow​_any:boolUndocumented
Returns
TypeUndocumented
def fix_instance(t, fail, note, disallow_any, python_version, use_generic_error=False, unexpanded_type=None): (source)

Fix a malformed instance by replacing all type arguments with Any.

Also emit a suitable error if this is not due to implicit Any's.

Parameters
t:InstanceUndocumented
fail:MsgCallbackUndocumented
note:MsgCallbackUndocumented
disallow​_any:boolUndocumented
python​_version:Tuple[int, int]Undocumented
use​_generic​_error:boolUndocumented
unexpanded​_type:Optional[Type]Undocumented
def fix_instance_types(t, fail, note, python_version): (source)

Recursively fix all instance types (type argument count) in a given type.

For example 'Union[Dict, List[str, int]]' will be transformed into 'Union[Dict[Any, Any], List[Any]]' in place.

Parameters
t:TypeUndocumented
fail:MsgCallbackUndocumented
note:MsgCallbackUndocumented
python​_version:Tuple[int, int]Undocumented
def flatten_tvars(ll): (source)

Undocumented

Parameters
ll:Iterable[List[T]]Undocumented
Returns
List[T]Undocumented
def get_omitted_any(disallow_any, fail, note, orig_type, python_version, fullname=None, unexpanded_type=None): (source)

Undocumented

Parameters
disallow​_any:boolUndocumented
fail:MsgCallbackUndocumented
note:MsgCallbackUndocumented
orig​_type:TypeUndocumented
python​_version:Tuple[int, int]Undocumented
fullname:Optional[str]Undocumented
unexpanded​_type:Optional[Type]Undocumented
Returns
AnyTypeUndocumented
def has_any_from_unimported_type(t): (source)

Return true if this type is Any because an import was not followed.

If type t is such Any type or has type arguments that contain such Any type this function will return true.

Parameters
t:TypeUndocumented
Returns
boolUndocumented
def has_explicit_any(t): (source)
Whether this type is or type it contains is an Any coming from explicit type annotation
Parameters
t:TypeUndocumented
Returns
boolUndocumented
def make_optional_type(t): (source)

Return the type corresponding to Optional[t].

Note that we can't use normal union simplification, since this function is called during semantic analysis and simplification only works during type checking.

Parameters
t:TypeUndocumented
Returns
TypeUndocumented
def no_subscript_builtin_alias(name, propose_alt=True): (source)

Undocumented

Parameters
name:strUndocumented
propose​_alt:boolUndocumented
Returns
strUndocumented
def remove_dups(tvars): (source)

Undocumented

Parameters
tvars:Iterable[T]Undocumented
Returns
List[T]Undocumented
def set_any_tvars(node, newline, newcolumn, *, from_error=False, disallow_any=False, fail=None, unexpanded_type=None): (source)

Undocumented

Parameters
node:TypeAliasUndocumented
newline:intUndocumented
newcolumn:intUndocumented
from​_error:boolUndocumented
disallow​_any:boolUndocumented
fail:Optional[MsgCallback]Undocumented
unexpanded​_type:Optional[Type]Undocumented
Returns
TypeUndocumented
ARG_KINDS_BY_CONSTRUCTOR = (source)

Undocumented

Value
{'mypy_extensions.Arg': ARG_POS,
 'mypy_extensions.DefaultArg': ARG_OPT,
 'mypy_extensions.NamedArg': ARG_NAMED,
 'mypy_extensions.DefaultNamedArg': ARG_NAMED_OPT,
 'mypy_extensions.VarArg': ARG_STAR,
 'mypy_extensions.KwArg': ARG_STAR2}
GENERIC_STUB_NOT_AT_RUNTIME_TYPES: set[str] = (source)

Undocumented

Value
set(['queue.Queue', 'builtins._PathLike', 'asyncio.futures.Future'])

Undocumented

Value
TypeVar('T')
type_constructors: set[str] = (source)

Undocumented

Value
set(['typing.Callable',
     'typing.Optional',
     'typing.Tuple',
     'typing.Type',
     'typing.Union',
     'typing.Literal',
     'typing_extensions.Literal',
...
MsgCallback = (source)

Undocumented

TypeVarLikeList = (source)

Undocumented