class documentation

class ExpressionChecker(ExpressionVisitor[Type]): (source)

View In Hierarchy

Expression type checker.

This class works closely together with checker.TypeChecker.

Method __init__ Construct an expression type checker.
Method accept Type check a node in the given type context. If allow_none_return is True and this expression is a call, allow it to return None. This applies only to this expression and not any subexpressions.
Method alias​_type​_in​_runtime​_context Get type of a type alias (could be generic) in a runtime expression.
Method always​_returns​_none Check if node refers to something explicitly annotated as only returning None.
Method analyze​_cond​_branch Undocumented
Method analyze​_external​_member​_access Analyse member access that is external, i.e. it cannot refer to private definitions. Return the result type.
Method analyze​_ordinary​_member​_access Analyse member expression or member lvalue.
Method analyze​_ref​_expr Undocumented
Method analyze​_type​_type​_callee Analyze the callee X in X(...) where X is Type[item].
Method analyze​_var​_ref Undocumented
Method apply​_function​_plugin Use special case logic to infer the return type of a specific named function/method.
Method apply​_function​_signature​_hook Apply a plugin hook that may infer a more precise signature for a function.
Method apply​_generic​_arguments Simple wrapper around mypy.applytype.apply_generic_arguments.
Method apply​_inferred​_arguments Apply inferred values of type arguments to a generic function.
Method apply​_method​_signature​_hook Apply a plugin hook that may infer a more precise signature for a method.
Method apply​_signature​_hook Helper to apply a signature hook for either a function or method
Method apply​_type​_arguments​_to​_callable Apply type arguments to a generic callable type coming from a type object.
Method argument​_infer​_context Undocumented
Method bool​_type Return instance type 'bool'.
Method check​_any​_type​_call Undocumented
Method check​_arg Check the type of a single argument in a call.
Method check​_argument​_count Check that there is a value for all required arguments to a function.
Method check​_argument​_types Check argument types against a callable type.
Method check​_awaitable​_expr Check the argument to await and extract the type of value.
Method check​_boolean​_op Type check a boolean operation ('and' or 'or').
Method check​_call Type check a call.
Method check​_call​_expr​_with​_callee​_type Type check call expression.
Method check​_callable​_call Type check a call that targets a callable value.
Method check​_for​_comp Check the for_comp part of comprehensions. That is the part from 'for': ... for x in y if z
Method check​_for​_extra​_actual​_arguments Check for extra actual arguments.
Method check​_generator​_or​_comprehension Type check a generator expression or a list comprehension.
Method check​_list​_multiply Type check an expression of form '[...] * e'.
Method check​_lst​_expr Undocumented
Method check​_method​_call Type check a call to a method with the given name and type on an object.
Method check​_method​_call​_by​_name Type check a call to a named method on an object.
Method check​_op Type check a binary operation which maps to a method call.
Method check​_op​_reversible Undocumented
Method check​_overload​_call Checks a call to an overloaded function.
Method check​_protocol​_issubclass Undocumented
Method check​_runtime​_protocol​_test Undocumented
Method check​_str​_format​_call More precise type checking for str.format() calls on literals.
Method check​_typeddict​_call Undocumented
Method check​_typeddict​_call​_with​_dict Undocumented
Method check​_typeddict​_call​_with​_kwargs Undocumented
Method check​_union​_call Undocumented
Method check​_union​_call​_expr "Type check calling a member expression where the base type is a union.
Method check​_union​_method​_call​_by​_name Type check a call to a named method on an object with union type.
Method combine​_function​_signatures Accepts a list of function signatures and attempts to combine them together into a new CallableType consisting of the union of all of the given arguments and return types.
Method concat​_tuples Concatenate two fixed length tuples.
Method dangerous​_comparison Check for dangerous non-overlapping comparisons like 42 == 'no'.
Method defn​_returns​_none Check if defn can _only_ return None.
Method erased​_signature​_similarity Determine whether arguments could match the signature at runtime, after erasing types.
Method fast​_container​_type Fast path to determine the type of a list or set literal, based on the list of entries. This mostly impacts large module-level constant definitions.
Method fast​_dict​_type Fast path to determine the type of a dict literal, based on the list of entries. This mostly impacts large module-level constant definitions.
Method find​_partial​_type​_ref​_fast​_path If expression has a partial generic type, return it without additional checks.
Method find​_typeddict​_context Undocumented
Method get​_arg​_infer​_passes Return pass numbers for args for two-pass argument type inference.
Method get​_operator​_method Undocumented
Method get​_partial​_self​_var Get variable node for a partial self attribute.
Method get​_partial​_var Undocumented
Method get​_reverse​_op​_method Undocumented
Method has​_member Does type have member with the given name?
Method infer​_arg​_types​_in​_context Infer argument expression types using a callable type as context.
Method infer​_arg​_types​_in​_empty​_context Infer argument expression types in an empty context.
Method infer​_function​_type​_arguments Infer the type arguments for a generic callee type.
Method infer​_function​_type​_arguments​_pass2 Perform second pass of generic function type argument inference.
Method infer​_function​_type​_arguments​_using​_context Unify callable return type to type context to infer type vars.
Method infer​_lambda​_type​_using​_context Try to infer lambda expression type using context.
Method infer​_literal​_expr​_type Analyzes the given literal expression and determines if we should be inferring an Instance type, a Literal[...] type, or an Instance that remembers the original literal. We...
Method infer​_overload​_return​_type Attempts to find the first matching callable from the given list.
Method is​_literal​_context Undocumented
Method is​_valid​_keyword​_var​_arg Is a type valid as a **kwargs argument?
Method is​_valid​_var​_arg Is a type valid as a *args argument?
Method match​_typeddict​_call​_with​_dict Undocumented
Method method​_fullname Convert a method name to a fully qualified name, based on the type of the object that it is invoked on. Return None if the name of object_type cannot be determined.
Method named​_type Return an instance type with type given by the name and no type arguments. Alias for TypeChecker.named_type.
Method narrow​_type​_from​_binder Narrow down a known type of expression using information in conditional type binder.
Method nonliteral​_tuple​_index​_helper Undocumented
Method not​_ready​_callback Called when we can't infer the type of a variable because it's not ready yet.
Method object​_type Return instance type 'object'.
Method overload​_erased​_call​_targets Returns a list of all targets that match the caller after erasing types.
Method plausible​_overload​_call​_targets Returns all overload call targets that having matching argument counts.
Method real​_union Undocumented
Method transform​_callee​_type Attempt to determine a more accurate signature for a method call.
Method try​_getting​_int​_literals If the given expression or type corresponds to an int literal or a union of int literals, returns a list of the underlying ints. Otherwise, returns None.
Method try​_infer​_partial​_type Try to make partial type precise from a call.
Method try​_infer​_partial​_value​_type​_from​_call Try to make partial type precise from a call such as 'x.append(y)'.
Method type​_overrides​_set Set _temporary_ type overrides for given expressions.
Method union​_overload​_result Accepts a list of overload signatures and attempts to match calls by destructuring the first union.
Method validate​_typeddict​_kwargs Undocumented
Method visit​_​_promote​_expr Undocumented
Method visit​_assignment​_expr Undocumented
Method visit​_await​_expr Undocumented
Method visit​_backquote​_expr Undocumented
Method visit​_bytes​_expr Type check a bytes literal (trivial).
Method visit​_call​_expr Type check a call expression.
Method visit​_call​_expr​_inner Undocumented
Method visit​_cast​_expr Type check a cast expression.
Method visit​_comparison​_expr Type check a comparison expression.
Method visit​_complex​_expr Type check a complex literal.
Method visit​_conditional​_expr Undocumented
Method visit​_dict​_expr Type check a dict expression.
Method visit​_dictionary​_comprehension Type check a dictionary comprehension.
Method visit​_ellipsis Type check '...'.
Method visit​_enum​_call​_expr Undocumented
Method visit​_enum​_index​_expr Undocumented
Method visit​_float​_expr Type check a float literal (trivial).
Method visit​_generator​_expr Undocumented
Method visit​_index​_expr Type check an index expression (base[index]).
Method visit​_index​_expr​_helper Undocumented
Method visit​_index​_with​_type Analyze type of an index expression for a given type of base expression.
Method visit​_int​_expr Type check an integer literal (trivial).
Method visit​_lambda​_expr Type check lambda expression.
Method visit​_list​_comprehension Undocumented
Method visit​_list​_expr Type check a list expression [...].
Method visit​_member​_expr Visit member expression (of form e.id).
Method visit​_name​_expr Type check a name expression.
Method visit​_namedtuple​_expr Undocumented
Method visit​_newtype​_expr Undocumented
Method visit​_op​_expr Type check a binary operator expression.
Method visit​_paramspec​_expr Undocumented
Method visit​_reveal​_expr Type check a reveal_type expression.
Method visit​_set​_comprehension Undocumented
Method visit​_set​_expr Undocumented
Method visit​_slice​_expr Undocumented
Method visit​_star​_expr Undocumented
Method visit​_str​_expr Type check a string literal (trivial).
Method visit​_super​_expr Type check a super expression (non-lvalue).
Method visit​_temp​_node Undocumented
Method visit​_tuple​_expr Type check a tuple expression.
Method visit​_tuple​_slice​_helper Undocumented
Method visit​_type​_alias​_expr Right hand side of a type alias definition.
Method visit​_type​_application Type check a type application (expr[type, ...]).
Method visit​_type​_var​_expr Undocumented
Method visit​_typeddict​_expr Undocumented
Method visit​_typeddict​_index​_expr Undocumented
Method visit​_unary​_expr Type check an unary operation ('not', '-', '+' or '~').
Method visit​_unicode​_expr Type check a unicode literal (trivial).
Method visit​_yield​_expr Undocumented
Method visit​_yield​_from​_expr Undocumented
Class Variable container​_args Undocumented
Class Variable item​_args Undocumented
Instance Variable chk Undocumented
Instance Variable msg Undocumented
Instance Variable plugin Undocumented
Instance Variable strfrm​_checker Undocumented
Instance Variable type​_context Undocumented
Instance Variable type​_overrides Undocumented
Method _super​_arg​_types Computes the types of the type and instance expressions in super(T, instance), or the implicit ones for zero-argument super() expressions. Returns a single type for the whole super expression when possible (for errors, anys), otherwise the pair of computed types.
def __init__(self, chk, msg, plugin): (source)
Construct an expression type checker.
Parameters
chk:mypy.checker.TypeCheckerUndocumented
msg:MessageBuilderUndocumented
plugin:PluginUndocumented
def accept(self, node, type_context=None, allow_none_return=False, always_allow_any=False): (source)
Type check a node in the given type context. If allow_none_return is True and this expression is a call, allow it to return None. This applies only to this expression and not any subexpressions.
Parameters
node:ExpressionUndocumented
type​_context:Optional[Type]Undocumented
allow​_none​_return:boolUndocumented
always​_allow​_any:boolUndocumented
Returns
TypeUndocumented
def alias_type_in_runtime_context(self, alias, no_args, ctx, *, alias_definition=False): (source)

Get type of a type alias (could be generic) in a runtime expression.

Note that this function can be called only if the alias appears _not_ as a target of type application, which is treated separately in the visit_type_application method. Some examples where this method is called are casts and instantiation:

class LongName(Generic[T]): ... A = LongName[int]

x = A() y = cast(A, ...)

Parameters
alias:TypeAliasUndocumented
no​_args:boolUndocumented
ctx:ContextUndocumented
alias​_definition:boolUndocumented
Returns
TypeUndocumented
def always_returns_none(self, node): (source)
Check if node refers to something explicitly annotated as only returning None.
Parameters
node:ExpressionUndocumented
Returns
boolUndocumented
def analyze_cond_branch(self, map, node, context, allow_none_return=False): (source)

Undocumented

Parameters
map:Optional[Dict[Expression, Type]]Undocumented
node:ExpressionUndocumented
context:Optional[Type]Undocumented
allow​_none​_return:boolUndocumented
Returns
TypeUndocumented
def analyze_external_member_access(self, member, base_type, context): (source)
Analyse member access that is external, i.e. it cannot refer to private definitions. Return the result type.
Parameters
member:strUndocumented
base​_type:TypeUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def analyze_ordinary_member_access(self, e, is_lvalue): (source)
Analyse member expression or member lvalue.
Parameters
e:MemberExprUndocumented
is​_lvalue:boolUndocumented
Returns
TypeUndocumented
def analyze_ref_expr(self, e, lvalue=False): (source)

Undocumented

Parameters
e:RefExprUndocumented
lvalue:boolUndocumented
Returns
TypeUndocumented
def analyze_type_type_callee(self, item, context): (source)

Analyze the callee X in X(...) where X is Type[item].

Return a Y that we can pass to check_call(Y, ...).

Parameters
item:ProperTypeUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def analyze_var_ref(self, var, context): (source)

Undocumented

Parameters
var:VarUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def apply_function_plugin(self, callee, arg_kinds, arg_types, arg_names, formal_to_actual, args, fullname, object_type, context): (source)

Use special case logic to infer the return type of a specific named function/method.

Caller must ensure that a plugin hook exists. There are two different cases:

  • If object_type is None, the caller must ensure that a function hook exists for fullname.
  • If object_type is not None, the caller must ensure that a method hook exists for fullname.

Return the inferred return type.

Parameters
callee:CallableTypeUndocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_types:List[Type]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
args:List[Expression]Undocumented
fullname:strUndocumented
object​_type:Optional[Type]Undocumented
context:ContextUndocumented
Returns
TypeUndocumented
def apply_function_signature_hook(self, callee, args, arg_kinds, context, arg_names, signature_hook): (source)
Apply a plugin hook that may infer a more precise signature for a function.
Parameters
callee:FunctionLikeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
signature​_hook:Callable[[FunctionSigContext], FunctionLike]Undocumented
Returns
FunctionLikeUndocumented
def apply_generic_arguments(self, callable, types, context, skip_unsatisfied=False): (source)
Simple wrapper around mypy.applytype.apply_generic_arguments.
Parameters
callable:CallableTypeUndocumented
types:Sequence[Optional[Type]]Undocumented
context:ContextUndocumented
skip​_unsatisfied:boolUndocumented
Returns
CallableTypeUndocumented
def apply_inferred_arguments(self, callee_type, inferred_args, context): (source)

Apply inferred values of type arguments to a generic function.

Inferred_args contains the values of function type arguments.

Parameters
callee​_type:CallableTypeUndocumented
inferred​_args:Sequence[Optional[Type]]Undocumented
context:ContextUndocumented
Returns
CallableTypeUndocumented
def apply_method_signature_hook(self, callee, args, arg_kinds, context, arg_names, object_type, signature_hook): (source)
Apply a plugin hook that may infer a more precise signature for a method.
Parameters
callee:FunctionLikeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
object​_type:TypeUndocumented
signature​_hook:Callable[[MethodSigContext], FunctionLike]Undocumented
Returns
FunctionLikeUndocumented
def apply_signature_hook(self, callee, args, arg_kinds, arg_names, hook): (source)
Helper to apply a signature hook for either a function or method
Parameters
callee:FunctionLikeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
hook:Callable[[List[List[Expression]], CallableType], FunctionLike]Undocumented
Returns
FunctionLikeUndocumented
def apply_type_arguments_to_callable(self, tp, args, ctx): (source)

Apply type arguments to a generic callable type coming from a type object.

This will first perform type arguments count checks, report the error as needed, and return the correct kind of Any. As a special case this returns Any for non-callable types, because if type object type is not callable, then an error should be already reported.

Parameters
tp:TypeUndocumented
args:Sequence[Type]Undocumented
ctx:ContextUndocumented
Returns
TypeUndocumented
def argument_infer_context(self): (source)

Undocumented

Returns
ArgumentInferContextUndocumented
def bool_type(self): (source)
Return instance type 'bool'.
Returns
InstanceUndocumented
def check_any_type_call(self, args, callee): (source)

Undocumented

Parameters
args:List[Expression]Undocumented
callee:TypeUndocumented
Returns
Tuple[Type, Type]Undocumented
def check_arg(self, caller_type, original_caller_type, caller_kind, callee_type, n, m, callee, object_type, context, outer_context, messages): (source)
Check the type of a single argument in a call.
Parameters
caller​_type:TypeUndocumented
original​_caller​_type:TypeUndocumented
caller​_kind:ArgKindUndocumented
callee​_type:TypeUndocumented
n:intUndocumented
m:intUndocumented
callee:CallableTypeUndocumented
object​_type:Optional[Type]Undocumented
context:ContextUndocumented
outer​_context:ContextUndocumented
messages:MessageBuilderUndocumented
def check_argument_count(self, callee, actual_types, actual_kinds, actual_names, formal_to_actual, context, messages): (source)

Check that there is a value for all required arguments to a function.

Also check that there are no duplicate values for arguments. Report found errors using 'messages' if it's not None. If 'messages' is given, 'context' must also be given.

Return False if there were any errors. Otherwise return True

Parameters
callee:CallableTypeUndocumented
actual​_types:List[Type]Undocumented
actual​_kinds:List[ArgKind]Undocumented
actual​_names:Optional[Sequence[Optional[str]]]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
context:Optional[Context]Undocumented
messages:Optional[MessageBuilder]Undocumented
Returns
boolUndocumented
def check_argument_types(self, arg_types, arg_kinds, args, callee, formal_to_actual, context, messages=None, check_arg=None, object_type=None): (source)

Check argument types against a callable type.

Report errors if the argument types are not compatible.

The check_call docstring describes some of the arguments.

Parameters
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
args:List[Expression]Undocumented
callee:CallableTypeUndocumented
formal​_to​_actual:List[List[int]]Undocumented
context:ContextUndocumented
messages:Optional[MessageBuilder]Undocumented
check​_arg:Optional[ArgChecker]Undocumented
object​_type:Optional[Type]Undocumented
def check_awaitable_expr(self, t, ctx, msg): (source)

Check the argument to await and extract the type of value.

Also used by async for and async with.

Parameters
t:TypeUndocumented
ctx:ContextUndocumented
msg:Union[str, ErrorMessage]Undocumented
Returns
TypeUndocumented
def check_boolean_op(self, e, context): (source)
Type check a boolean operation ('and' or 'or').
Parameters
e:OpExprUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def check_call(self, callee, args, arg_kinds, context, arg_names=None, callable_node=None, arg_messages=None, callable_name=None, object_type=None): (source)

Type check a call.

Also infer type arguments if the callee is a generic function.

Return (result type, inferred callee type).

Arguments:

callee: type of the called value args: actual argument expressions arg_kinds: contains nodes.ARG_* constant for each argument in args

describing whether the argument is positional, *arg, etc.

context: current expression context, used for inference. arg_names: names of arguments (optional) callable_node: associate the inferred callable type to this node,

if specified
arg_messages: utility for generating messages, can be swapped to suppress errors,
by default uses 'self.msg' to show errors
callable_name: Fully-qualified name of the function/method to call,
or None if unavailable (examples: 'builtins.open', 'typing.Mapping.get')
object_type: If callable_name refers to a method, the type of the object
on which the method is being called
Parameters
callee:TypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
callable​_node:Optional[Expression]Undocumented
arg​_messages:Optional[MessageBuilder]Undocumented
callable​_name:Optional[str]Undocumented
object​_type:Optional[Type]Undocumented
Returns
Tuple[Type, Type]Undocumented
def check_call_expr_with_callee_type(self, callee_type, e, callable_name, object_type, member=None): (source)

Type check call expression.

The callee_type should be used as the type of callee expression. In particular, in case of a union type this can be a particular item of the union, so that we can apply plugin hooks to each item.

The 'member', 'callable_name' and 'object_type' are only used to call plugin hooks. If 'callable_name' is None but 'member' is not None (member call), try constructing 'callable_name' using 'object_type' (the base type on which the method is called), for example 'typing.Mapping.get'.

Parameters
callee​_type:TypeUndocumented
e:CallExprUndocumented
callable​_name:Optional[str]Undocumented
object​_type:Optional[Type]Undocumented
member:Optional[str]Undocumented
Returns
TypeUndocumented
def check_callable_call(self, callee, args, arg_kinds, context, arg_names, callable_node, arg_messages, callable_name, object_type): (source)

Type check a call that targets a callable value.

See the docstring of check_call for more information.

Parameters
callee:CallableTypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
callable​_node:Optional[Expression]Undocumented
arg​_messages:MessageBuilderUndocumented
callable​_name:Optional[str]Undocumented
object​_type:Optional[Type]Undocumented
Returns
Tuple[Type, Type]Undocumented
def check_for_comp(self, e): (source)

Check the for_comp part of comprehensions. That is the part from 'for': ... for x in y if z

Note: This adds the type information derived from the condlists to the current binder.

Parameters
e:Union[GeneratorExpr, DictionaryComprehension]Undocumented
def check_for_extra_actual_arguments(self, callee, actual_types, actual_kinds, actual_names, all_actuals, context, messages): (source)

Check for extra actual arguments.

Return tuple (was everything ok,
was there an extra keyword argument error [used to avoid duplicate errors]).
Parameters
callee:CallableTypeUndocumented
actual​_types:List[Type]Undocumented
actual​_kinds:List[ArgKind]Undocumented
actual​_names:Optional[Sequence[Optional[str]]]Undocumented
all​_actuals:List[int]Undocumented
context:ContextUndocumented
messages:Optional[MessageBuilder]Undocumented
Returns
Tuple[bool, bool]Undocumented
def check_generator_or_comprehension(self, gen, type_name, id_for_messages, additional_args=None): (source)
Type check a generator expression or a list comprehension.
Parameters
gen:GeneratorExprUndocumented
type​_name:strUndocumented
id​_for​_messages:strUndocumented
additional​_args:Optional[List[Type]]Undocumented
Returns
TypeUndocumented
def check_list_multiply(self, e): (source)

Type check an expression of form '[...] * e'.

Type inference is special-cased for this common construct.

Parameters
e:OpExprUndocumented
Returns
TypeUndocumented
def check_lst_expr(self, items, fullname, tag, context): (source)

Undocumented

Parameters
items:List[Expression]Undocumented
fullname:strUndocumented
tag:strUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def check_method_call(self, method_name, base_type, method_type, args, arg_kinds, context, local_errors=None): (source)

Type check a call to a method with the given name and type on an object.

Return tuple (result type, inferred method type).

Parameters
method​_name:strUndocumented
base​_type:TypeUndocumented
method​_type:TypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
local​_errors:Optional[MessageBuilder]Undocumented
Returns
Tuple[Type, Type]Undocumented
def check_method_call_by_name(self, method, base_type, args, arg_kinds, context, local_errors=None, original_type=None): (source)

Type check a call to a named method on an object.

Return tuple (result type, inferred method type). The 'original_type' is used for error messages.

Parameters
method:strUndocumented
base​_type:TypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
local​_errors:Optional[MessageBuilder]Undocumented
original​_type:Optional[Type]Undocumented
Returns
Tuple[Type, Type]Undocumented
def check_op(self, method, base_type, arg, context, allow_reverse=False): (source)

Type check a binary operation which maps to a method call.

Return tuple (result type, inferred operator method type).

Parameters
method:strUndocumented
base​_type:TypeUndocumented
arg:ExpressionUndocumented
context:ContextUndocumented
allow​_reverse:boolUndocumented
Returns
Tuple[Type, Type]Undocumented
def check_op_reversible(self, op_name, left_type, left_expr, right_type, right_expr, context, msg): (source)

Undocumented

Parameters
op​_name:strUndocumented
left​_type:TypeUndocumented
left​_expr:ExpressionUndocumented
right​_type:TypeUndocumented
right​_expr:ExpressionUndocumented
context:ContextUndocumented
msg:MessageBuilderUndocumented
Returns
Tuple[Type, Type]Undocumented
def check_overload_call(self, callee, args, arg_kinds, arg_names, callable_name, object_type, context, arg_messages): (source)
Checks a call to an overloaded function.
Parameters
callee:OverloadedUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
callable​_name:Optional[str]Undocumented
object​_type:Optional[Type]Undocumented
context:ContextUndocumented
arg​_messages:MessageBuilderUndocumented
Returns
Tuple[Type, Type]Undocumented
def check_protocol_issubclass(self, e): (source)

Undocumented

Parameters
e:CallExprUndocumented
def check_runtime_protocol_test(self, e): (source)

Undocumented

Parameters
e:CallExprUndocumented
def check_str_format_call(self, e): (source)
More precise type checking for str.format() calls on literals.
Parameters
e:CallExprUndocumented
def check_typeddict_call(self, callee, arg_kinds, arg_names, args, context): (source)

Undocumented

Parameters
callee:TypedDictTypeUndocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Sequence[Optional[str]]Undocumented
args:List[Expression]Undocumented
context:ContextUndocumented
Returns
TypeUndocumented
def check_typeddict_call_with_dict(self, callee, kwargs, context): (source)

Undocumented

Parameters
callee:TypedDictTypeUndocumented
kwargs:DictExprUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def check_typeddict_call_with_kwargs(self, callee, kwargs, context): (source)

Undocumented

Parameters
callee:TypedDictTypeUndocumented
kwargs:OrderedDict[str, Expression]Undocumented
context:ContextUndocumented
Returns
TypeUndocumented
def check_union_call(self, callee, args, arg_kinds, arg_names, context, arg_messages): (source)

Undocumented

Parameters
callee:UnionTypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
context:ContextUndocumented
arg​_messages:MessageBuilderUndocumented
Returns
Tuple[Type, Type]Undocumented
def check_union_call_expr(self, e, object_type, member): (source)
"Type check calling a member expression where the base type is a union.
Parameters
e:CallExprUndocumented
object​_type:UnionTypeUndocumented
member:strUndocumented
Returns
TypeUndocumented
def check_union_method_call_by_name(self, method, base_type, args, arg_kinds, context, local_errors, original_type=None): (source)

Type check a call to a named method on an object with union type.

This essentially checks the call using check_method_call_by_name() for each union item and unions the result. We do this to allow plugins to act on individual union items.

Parameters
method:strUndocumented
base​_type:UnionTypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
local​_errors:MessageBuilderUndocumented
original​_type:Optional[Type]Undocumented
Returns
Tuple[Type, Type]Undocumented
def combine_function_signatures(self, types): (source)

Accepts a list of function signatures and attempts to combine them together into a new CallableType consisting of the union of all of the given arguments and return types.

If there is at least one non-callable type, return Any (this can happen if there is an ambiguity because of Any in arguments).

Parameters
types:Sequence[Type]Undocumented
Returns
Union[AnyType, CallableType]Undocumented
def concat_tuples(self, left, right): (source)
Concatenate two fixed length tuples.
Parameters
left:TupleTypeUndocumented
right:TupleTypeUndocumented
Returns
TupleTypeUndocumented
def dangerous_comparison(self, left, right, original_container=None): (source)

Check for dangerous non-overlapping comparisons like 42 == 'no'.

The original_container is the original container type for 'in' checks (and None for equality checks).

Rules:
  • X and None are overlapping even in strict-optional mode. This is to allow

'assert x is not None' for x defined as 'x = None # type: str' in class body (otherwise mypy itself would have couple dozen errors because of this). * Optional[X] and Optional[Y] are non-overlapping if X and Y are non-overlapping, although technically None is overlap, it is most likely an error. * Any overlaps with everything, i.e. always safe. * Special case: b'abc' in b'cde' is safe.

Parameters
left:TypeUndocumented
right:TypeUndocumented
original​_container:Optional[Type]Undocumented
Returns
boolUndocumented
def defn_returns_none(self, defn): (source)
Check if defn can _only_ return None.
Parameters
defn:Optional[SymbolNode]Undocumented
Returns
boolUndocumented
def erased_signature_similarity(self, arg_types, arg_kinds, arg_names, args, callee, context): (source)
Determine whether arguments could match the signature at runtime, after erasing types.
Parameters
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
args:List[Expression]Undocumented
callee:CallableTypeUndocumented
context:ContextUndocumented
Returns
boolUndocumented
def fast_container_type(self, items, container_fullname): (source)

Fast path to determine the type of a list or set literal, based on the list of entries. This mostly impacts large module-level constant definitions.

Limitations:
  • no active type context
  • no star expressions
  • the joined type of all entries must be an Instance type
Parameters
items:List[Expression]Undocumented
container​_fullname:strUndocumented
Returns
Optional[Type]Undocumented
def fast_dict_type(self, e): (source)

Fast path to determine the type of a dict literal, based on the list of entries. This mostly impacts large module-level constant definitions.

Limitations:
  • no active type context
  • only supported star expressions are other dict instances
  • the joined types of all keys and values must be Instance types
Parameters
e:DictExprUndocumented
Returns
Optional[Type]Undocumented
def find_partial_type_ref_fast_path(self, expr): (source)

If expression has a partial generic type, return it without additional checks.

In particular, this does not generate an error about a missing annotation.

Otherwise, return None.

Parameters
expr:ExpressionUndocumented
Returns
Optional[Type]Undocumented
def find_typeddict_context(self, context, dict_expr): (source)

Undocumented

Parameters
context:Optional[Type]Undocumented
dict​_expr:DictExprUndocumented
Returns
Optional[TypedDictType]Undocumented
def get_arg_infer_passes(self, arg_types, formal_to_actual, num_actuals): (source)

Return pass numbers for args for two-pass argument type inference.

For each actual, the pass number is either 1 (first pass) or 2 (second pass).

Two-pass argument type inference primarily lets us infer types of lambdas more effectively.

Parameters
arg​_types:List[Type]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
num​_actuals:intUndocumented
Returns
List[int]Undocumented
def get_operator_method(self, op): (source)

Undocumented

Parameters
op:strUndocumented
Returns
strUndocumented
def get_partial_self_var(self, expr): (source)

Get variable node for a partial self attribute.

If the expression is not a self attribute, or attribute is not variable, or variable is not partial, return None.

Parameters
expr:MemberExprUndocumented
Returns
Optional[Var]Undocumented
def get_partial_var(self, ref): (source)

Undocumented

Parameters
ref:RefExprUndocumented
Returns
Optional[Tuple[Var, Dict[Var, Context]]]Undocumented
def get_reverse_op_method(self, method): (source)

Undocumented

Parameters
method:strUndocumented
Returns
strUndocumented
def has_member(self, typ, member): (source)
Does type have member with the given name?
Parameters
typ:TypeUndocumented
member:strUndocumented
Returns
boolUndocumented
def infer_arg_types_in_context(self, callee, args, arg_kinds, formal_to_actual): (source)

Infer argument expression types using a callable type as context.

For example, if callee argument 2 has type List[int], infer the argument expression with List[int] type context.

Returns the inferred types of actual arguments.

Parameters
callee:CallableTypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
Returns
List[Type]Undocumented
def infer_arg_types_in_empty_context(self, args): (source)

Infer argument expression types in an empty context.

In short, we basically recurse on each argument without considering in what context the argument was called.

Parameters
args:List[Expression]Undocumented
Returns
List[Type]Undocumented
def infer_function_type_arguments(self, callee_type, args, arg_kinds, formal_to_actual, context): (source)

Infer the type arguments for a generic callee type.

Infer based on the types of arguments.

Return a derived callable type that has the arguments applied.

Parameters
callee​_type:CallableTypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
context:ContextUndocumented
Returns
CallableTypeUndocumented
def infer_function_type_arguments_pass2(self, callee_type, args, arg_kinds, formal_to_actual, old_inferred_args, context): (source)

Perform second pass of generic function type argument inference.

The second pass is needed for arguments with types such as Callable[[T], S], where both T and S are type variables, when the actual argument is a lambda with inferred types. The idea is to infer the type variable T in the first pass (based on the types of other arguments). This lets us infer the argument and return type of the lambda expression and thus also the type variable S in this second pass.

Return (the callee with type vars applied, inferred actual arg types).

Parameters
callee​_type:CallableTypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
old​_inferred​_args:Sequence[Optional[Type]]Undocumented
context:ContextUndocumented
Returns
Tuple[CallableType, List[Optional[Type]]]Undocumented
def infer_function_type_arguments_using_context(self, callable, error_context): (source)

Unify callable return type to type context to infer type vars.

For example, if the return type is set[t] where 't' is a type variable of callable, and if the context is set[int], return callable modified by substituting 't' with 'int'.

Parameters
callable:CallableTypeUndocumented
error​_context:ContextUndocumented
Returns
CallableTypeUndocumented
def infer_lambda_type_using_context(self, e): (source)

Try to infer lambda expression type using context.

Return None if could not infer type. The second item in the return type is the type_override parameter for check_func_item.

Parameters
e:LambdaExprUndocumented
Returns
Tuple[Optional[CallableType], Optional[CallableType]]Undocumented
def infer_literal_expr_type(self, value, fallback_name): (source)

Analyzes the given literal expression and determines if we should be inferring an Instance type, a Literal[...] type, or an Instance that remembers the original literal. We...

  1. ...Infer a normal Instance in most circumstances.
  2. ...Infer a Literal[...] if we're in a literal context. For example, if we were analyzing the "3" in "foo(3)" where "foo" has a signature of "def foo(Literal[3]) -> None", we'd want to infer that the "3" has a type of Literal[3] instead of Instance.
  3. ...Infer an Instance that remembers the original Literal if we're declaring a Final variable with an inferred type -- for example, "bar" in "bar: Final = 3" would be assigned an Instance that remembers it originated from a '3'. See the comments in Instance's constructor for more details.
Parameters
value:LiteralValueUndocumented
fallback​_name:strUndocumented
Returns
TypeUndocumented
def infer_overload_return_type(self, plausible_targets, args, arg_types, arg_kinds, arg_names, callable_name, object_type, context, arg_messages=None): (source)

Attempts to find the first matching callable from the given list.

If a match is found, returns a tuple containing the result type and the inferred callee type. (This tuple is meant to be eventually returned by check_call.) If multiple targets match due to ambiguous Any parameters, returns (AnyType, AnyType). If no targets match, returns None.

Assumes all of the given targets have argument counts compatible with the caller.

Parameters
plausible​_targets:List[CallableType]Undocumented
args:List[Expression]Undocumented
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
callable​_name:Optional[str]Undocumented
object​_type:Optional[Type]Undocumented
context:ContextUndocumented
arg​_messages:Optional[MessageBuilder]Undocumented
Returns
Optional[Tuple[Type, Type]]Undocumented
def is_literal_context(self): (source)

Undocumented

Returns
boolUndocumented
def is_valid_keyword_var_arg(self, typ): (source)
Is a type valid as a **kwargs argument?
Parameters
typ:TypeUndocumented
Returns
boolUndocumented
def is_valid_var_arg(self, typ): (source)
Is a type valid as a *args argument?
Parameters
typ:TypeUndocumented
Returns
boolUndocumented
def match_typeddict_call_with_dict(self, callee, kwargs, context): (source)

Undocumented

Parameters
callee:TypedDictTypeUndocumented
kwargs:DictExprUndocumented
context:ContextUndocumented
Returns
boolUndocumented
def method_fullname(self, object_type, method_name): (source)
Convert a method name to a fully qualified name, based on the type of the object that it is invoked on. Return None if the name of object_type cannot be determined.
Parameters
object​_type:TypeUndocumented
method​_name:strUndocumented
Returns
Optional[str]Undocumented
def named_type(self, name): (source)
Return an instance type with type given by the name and no type arguments. Alias for TypeChecker.named_type.
Parameters
name:strUndocumented
Returns
InstanceUndocumented
def narrow_type_from_binder(self, expr, known_type, skip_non_overlapping=False): (source)

Narrow down a known type of expression using information in conditional type binder.

If 'skip_non_overlapping' is True, return None if the type and restriction are non-overlapping.

Parameters
expr:ExpressionUndocumented
known​_type:TypeUndocumented
skip​_non​_overlapping:boolUndocumented
Returns
Optional[Type]Undocumented
def nonliteral_tuple_index_helper(self, left_type, index): (source)

Undocumented

Parameters
left​_type:TupleTypeUndocumented
index:ExpressionUndocumented
Returns
TypeUndocumented
def not_ready_callback(self, name, context): (source)

Called when we can't infer the type of a variable because it's not ready yet.

Either defer type checking of the enclosing function to the next pass or report an error.

Parameters
name:strUndocumented
context:ContextUndocumented
def object_type(self): (source)
Return instance type 'object'.
Returns
InstanceUndocumented
def overload_erased_call_targets(self, plausible_targets, arg_types, arg_kinds, arg_names, args, context): (source)

Returns a list of all targets that match the caller after erasing types.

Assumes all of the given targets have argument counts compatible with the caller.

Parameters
plausible​_targets:List[CallableType]Undocumented
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
args:List[Expression]Undocumented
context:ContextUndocumented
Returns
List[CallableType]Undocumented
def plausible_overload_call_targets(self, arg_types, arg_kinds, arg_names, overload): (source)

Returns all overload call targets that having matching argument counts.

If the given args contains a star-arg (*arg or **kwarg argument), this method will ensure all star-arg overloads appear at the start of the list, instead of their usual location.

The only exception is if the starred argument is something like a Tuple or a NamedTuple, which has a definitive "shape". If so, we don't move the corresponding alternative to the front since we can infer a more precise match using the original order.

Parameters
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
overload:OverloadedUndocumented
Returns
List[CallableType]Undocumented
def real_union(self, typ): (source)

Undocumented

Parameters
typ:TypeUndocumented
Returns
boolUndocumented
def transform_callee_type(self, callable_name, callee, args, arg_kinds, context, arg_names=None, object_type=None): (source)

Attempt to determine a more accurate signature for a method call.

This is done by looking up and applying a method signature hook (if one exists for the given method name).

If no matching method signature hook is found, callee is returned unmodified. The same happens if the arguments refer to a non-method callable (this is allowed so that the code calling transform_callee_type needs to perform fewer boilerplate checks).

Note: this method is not called automatically as part of check_call, because in some cases check_call is called multiple times while checking a single call (for example when dealing with overloads). Instead, this method needs to be called explicitly (if appropriate) before the signature is passed to check_call.

Parameters
callable​_name:Optional[str]Undocumented
callee:TypeUndocumented
args:List[Expression]Undocumented
arg​_kinds:List[ArgKind]Undocumented
context:ContextUndocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
object​_type:Optional[Type]Undocumented
Returns
TypeUndocumented
def try_getting_int_literals(self, index): (source)

If the given expression or type corresponds to an int literal or a union of int literals, returns a list of the underlying ints. Otherwise, returns None.

Specifically, this function is guaranteed to return a list with one or more ints if one one the following is true:

  1. 'expr' is a IntExpr or a UnaryExpr backed by an IntExpr
  2. 'typ' is a LiteralType containing an int
  3. 'typ' is a UnionType containing only LiteralType of ints
Parameters
index:ExpressionUndocumented
Returns
Optional[List[int]]Undocumented
def try_infer_partial_type(self, e): (source)
Try to make partial type precise from a call.
Parameters
e:CallExprUndocumented
def try_infer_partial_value_type_from_call(self, e, methodname, var): (source)
Try to make partial type precise from a call such as 'x.append(y)'.
Parameters
e:CallExprUndocumented
methodname:strUndocumented
var:VarUndocumented
Returns
Optional[Instance]Undocumented
@contextmanager
def type_overrides_set(self, exprs, overrides): (source)
Set _temporary_ type overrides for given expressions.
Parameters
exprs:Sequence[Expression]Undocumented
overrides:Sequence[Type]Undocumented
Returns
Iterator[None]Undocumented
def union_overload_result(self, plausible_targets, args, arg_types, arg_kinds, arg_names, callable_name, object_type, context, arg_messages=None, level=0): (source)

Accepts a list of overload signatures and attempts to match calls by destructuring the first union.

Return a list of (<return type>, <inferred variant type>) if call succeeds for every item of the desctructured union. Returns None if there is no match.

Parameters
plausible​_targets:List[CallableType]Undocumented
args:List[Expression]Undocumented
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
callable​_name:Optional[str]Undocumented
object​_type:Optional[Type]Undocumented
context:ContextUndocumented
arg​_messages:Optional[MessageBuilder]Undocumented
level:intUndocumented
Returns
Optional[List[Tuple[Type, Type]]]Undocumented
def validate_typeddict_kwargs(self, kwargs): (source)

Undocumented

Parameters
kwargs:DictExprUndocumented
Returns
Optional[OrderedDict[str, Expression]]Undocumented
def visit__promote_expr(self, e): (source)

Undocumented

Parameters
e:PromoteExprUndocumented
Returns
TypeUndocumented
def visit_assignment_expr(self, e): (source)

Undocumented

Parameters
e:AssignmentExprUndocumented
Returns
TypeUndocumented
def visit_await_expr(self, e): (source)

Undocumented

Parameters
e:AwaitExprUndocumented
Returns
TypeUndocumented
def visit_backquote_expr(self, e): (source)

Undocumented

Parameters
e:BackquoteExprUndocumented
Returns
TypeUndocumented
def visit_bytes_expr(self, e): (source)
Type check a bytes literal (trivial).
Parameters
e:BytesExprUndocumented
Returns
TypeUndocumented
def visit_call_expr(self, e, allow_none_return=False): (source)
Type check a call expression.
Parameters
e:CallExprUndocumented
allow​_none​_return:boolUndocumented
Returns
TypeUndocumented
def visit_call_expr_inner(self, e, allow_none_return=False): (source)

Undocumented

Parameters
e:CallExprUndocumented
allow​_none​_return:boolUndocumented
Returns
TypeUndocumented
def visit_cast_expr(self, expr): (source)
Type check a cast expression.
Parameters
expr:CastExprUndocumented
Returns
TypeUndocumented
def visit_comparison_expr(self, e): (source)

Type check a comparison expression.

Comparison expressions are type checked consecutive-pair-wise That is, 'a < b > c == d' is check as 'a < b and b > c and c == d'

Parameters
e:ComparisonExprUndocumented
Returns
TypeUndocumented
def visit_complex_expr(self, e): (source)
Type check a complex literal.
Parameters
e:ComplexExprUndocumented
Returns
TypeUndocumented
def visit_conditional_expr(self, e, allow_none_return=False): (source)

Undocumented

Parameters
e:ConditionalExprUndocumented
allow​_none​_return:boolUndocumented
Returns
TypeUndocumented
def visit_dict_expr(self, e): (source)

Type check a dict expression.

Translate it into a call to dict(), with provisions for **expr.

Parameters
e:DictExprUndocumented
Returns
TypeUndocumented
def visit_dictionary_comprehension(self, e): (source)
Type check a dictionary comprehension.
Parameters
e:DictionaryComprehensionUndocumented
Returns
TypeUndocumented
def visit_ellipsis(self, e): (source)
Type check '...'.
Parameters
e:EllipsisExprUndocumented
Returns
TypeUndocumented
def visit_enum_call_expr(self, e): (source)

Undocumented

Parameters
e:EnumCallExprUndocumented
Returns
TypeUndocumented
def visit_enum_index_expr(self, enum_type, index, context): (source)

Undocumented

Parameters
enum​_type:TypeInfoUndocumented
index:ExpressionUndocumented
context:ContextUndocumented
Returns
TypeUndocumented
def visit_float_expr(self, e): (source)
Type check a float literal (trivial).
Parameters
e:FloatExprUndocumented
Returns
TypeUndocumented
def visit_generator_expr(self, e): (source)

Undocumented

Parameters
e:GeneratorExprUndocumented
Returns
TypeUndocumented
def visit_index_expr(self, e): (source)

Type check an index expression (base[index]).

It may also represent type application.

Parameters
e:IndexExprUndocumented
Returns
TypeUndocumented
def visit_index_expr_helper(self, e): (source)

Undocumented

Parameters
e:IndexExprUndocumented
Returns
TypeUndocumented
def visit_index_with_type(self, left_type, e, original_type=None): (source)

Analyze type of an index expression for a given type of base expression.

The 'original_type' is used for error messages (currently used for union types).

Parameters
left​_type:TypeUndocumented
e:IndexExprUndocumented
original​_type:Optional[ProperType]Undocumented
Returns
TypeUndocumented
def visit_int_expr(self, e): (source)
Type check an integer literal (trivial).
Parameters
e:IntExprUndocumented
Returns
TypeUndocumented
def visit_lambda_expr(self, e): (source)
Type check lambda expression.
Parameters
e:LambdaExprUndocumented
Returns
TypeUndocumented
def visit_list_comprehension(self, e): (source)

Undocumented

Parameters
e:ListComprehensionUndocumented
Returns
TypeUndocumented
def visit_list_expr(self, e): (source)
Type check a list expression [...].
Parameters
e:ListExprUndocumented
Returns
TypeUndocumented
def visit_member_expr(self, e, is_lvalue=False): (source)
Visit member expression (of form e.id).
Parameters
e:MemberExprUndocumented
is​_lvalue:boolUndocumented
Returns
TypeUndocumented
def visit_name_expr(self, e): (source)

Type check a name expression.

It can be of any kind: local, member or global.

Parameters
e:NameExprUndocumented
Returns
TypeUndocumented
def visit_namedtuple_expr(self, e): (source)

Undocumented

Parameters
e:NamedTupleExprUndocumented
Returns
TypeUndocumented
def visit_newtype_expr(self, e): (source)

Undocumented

Parameters
e:NewTypeExprUndocumented
Returns
TypeUndocumented
def visit_op_expr(self, e): (source)
Type check a binary operator expression.
Parameters
e:OpExprUndocumented
Returns
TypeUndocumented
def visit_paramspec_expr(self, e): (source)

Undocumented

Parameters
e:ParamSpecExprUndocumented
Returns
TypeUndocumented
def visit_reveal_expr(self, expr): (source)
Type check a reveal_type expression.
Parameters
expr:RevealExprUndocumented
Returns
TypeUndocumented
def visit_set_comprehension(self, e): (source)

Undocumented

Parameters
e:SetComprehensionUndocumented
Returns
TypeUndocumented
def visit_set_expr(self, e): (source)

Undocumented

Parameters
e:SetExprUndocumented
Returns
TypeUndocumented
def visit_slice_expr(self, e): (source)

Undocumented

Parameters
e:SliceExprUndocumented
Returns
TypeUndocumented
def visit_star_expr(self, e): (source)

Undocumented

Parameters
e:StarExprUndocumented
Returns
StarTypeUndocumented
def visit_str_expr(self, e): (source)
Type check a string literal (trivial).
Parameters
e:StrExprUndocumented
Returns
TypeUndocumented
def visit_super_expr(self, e): (source)
Type check a super expression (non-lvalue).
Parameters
e:SuperExprUndocumented
Returns
TypeUndocumented
def visit_temp_node(self, e): (source)

Undocumented

Parameters
e:TempNodeUndocumented
Returns
TypeUndocumented
def visit_tuple_expr(self, e): (source)
Type check a tuple expression.
Parameters
e:TupleExprUndocumented
Returns
TypeUndocumented
def visit_tuple_slice_helper(self, left_type, slic): (source)

Undocumented

Parameters
left​_type:TupleTypeUndocumented
slic:SliceExprUndocumented
Returns
TypeUndocumented
def visit_type_alias_expr(self, alias): (source)

Right hand side of a type alias definition.

It has the same type as if the alias itself was used in a runtime context. For example, here:

A = reveal_type(List[T]) reveal_type(A)

both reveal_type instances will reveal the same type def (...) -> builtins.list[Any]. Note that type variables are implicitly substituted with Any.

Parameters
alias:TypeAliasExprUndocumented
Returns
TypeUndocumented
def visit_type_application(self, tapp): (source)

Type check a type application (expr[type, ...]).

There are two different options here, depending on whether expr refers to a type alias or directly to a generic class. In the first case we need to use a dedicated function typeanal.expand_type_aliases. This is due to the fact that currently type aliases machinery uses unbound type variables, while normal generics use bound ones; see TypeAlias docstring for more details.

Parameters
tapp:TypeApplicationUndocumented
Returns
TypeUndocumented
def visit_type_var_expr(self, e): (source)

Undocumented

Parameters
e:TypeVarExprUndocumented
Returns
TypeUndocumented
def visit_typeddict_expr(self, e): (source)

Undocumented

Parameters
e:TypedDictExprUndocumented
Returns
TypeUndocumented
def visit_typeddict_index_expr(self, td_type, index): (source)

Undocumented

Parameters
td​_type:TypedDictTypeUndocumented
index:ExpressionUndocumented
Returns
TypeUndocumented
def visit_unary_expr(self, e): (source)
Type check an unary operation ('not', '-', '+' or '~').
Parameters
e:UnaryExprUndocumented
Returns
TypeUndocumented
def visit_unicode_expr(self, e): (source)
Type check a unicode literal (trivial).
Parameters
e:UnicodeExprUndocumented
Returns
TypeUndocumented
def visit_yield_expr(self, e): (source)

Undocumented

Parameters
e:YieldExprUndocumented
Returns
TypeUndocumented
def visit_yield_from_expr(self, e, allow_none_return=False): (source)

Undocumented

Parameters
e:YieldFromExprUndocumented
allow​_none​_return:boolUndocumented
Returns
TypeUndocumented
container_args: ClassVar[Dict[str, Dict[str, List[str]]]] = (source)

Undocumented

item_args: ClassVar[Dict[str, List[str]]] = (source)

Undocumented

Undocumented

Undocumented

plugin = (source)

Undocumented

strfrm_checker = (source)

Undocumented

type_context: list = (source)

Undocumented

type_overrides: Dict[Expression, Type] = (source)

Undocumented

def _super_arg_types(self, e): (source)
Computes the types of the type and instance expressions in super(T, instance), or the implicit ones for zero-argument super() expressions. Returns a single type for the whole super expression when possible (for errors, anys), otherwise the pair of computed types.
Parameters
e:SuperExprUndocumented
Returns
Union[Type, Tuple[Type, Type]]Undocumented