module documentation
(source)

Expression type checker. This file is conceptually part of TypeChecker.
Class ​Arg​Infer​Second​Pass​Query Query whether an argument type should be inferred in the second pass.
Class ​Expression​Checker Expression type checker.
Class ​Finished Raised if we can terminate overload argument check early (no match).
Class ​Has​Any​Type Undocumented
Class ​Has​Erased​Components​Query Visitor for querying whether a type has an erased component.
Class ​Has​Type​Var​Query Visitor for querying whether a type has a type variable component.
Class ​Has​Uninhabited​Components​Query Visitor for querying whether a type has an UninhabitedType component.
Class ​Too​Many​Unions Indicates that we need to stop splitting unions in an attempt to match an overload in order to save performance.
Function all​_same​_types Undocumented
Function any​_causes​_overload​_ambiguity May an argument containing 'Any' cause ambiguous result type on call to overloaded function?
Function arg​_approximate​_similarity Return if caller argument (actual) is roughly compatible with signature arg (formal).
Function extract​_refexpr​_names Recursively extracts all module references from a reference expression.
Function get​_partial​_instance​_type Undocumented
Function has​_any​_type Whether t contains an Any type
Function has​_bytes​_component Is this one of builtin byte types, or a union that contains it?
Function has​_coroutine​_decorator Whether t came from a function decorated with @coroutine.
Function has​_erased​_component Undocumented
Function has​_uninhabited​_component Undocumented
Function is​_async​_def Whether t came from a function defined using async def.
Function is​_duplicate​_mapping Undocumented
Function is​_expr​_literal​_type Returns 'true' if the given node is a Literal
Function is​_non​_empty​_tuple Undocumented
Function is​_operator​_method Undocumented
Function merge​_typevars​_in​_callables​_by​_name Takes all the typevars present in the callables and 'combines' the ones with the same name.
Function replace​_callable​_return​_type Return a copy of a callable type with a different return type.
Function try​_getting​_literal If possible, get a more precise literal type for a given type.
Function type​_info​_from​_type Gets the TypeInfo for a type, indirecting through things like type variables and tuples.
Constant MAX​_UNIONS Undocumented
Constant OVERLAPPING​_TYPES​_ALLOWLIST Undocumented
Variable ​Arg​Checker Undocumented
def all_same_types(types): (source)

Undocumented

Parameters
types:List[Type]Undocumented
Returns
boolUndocumented
def any_causes_overload_ambiguity(items, return_types, arg_types, arg_kinds, arg_names): (source)

May an argument containing 'Any' cause ambiguous result type on call to overloaded function?

Note that this sometimes returns True even if there is no ambiguity, since a correct implementation would be complex (and the call would be imprecisely typed due to Any types anyway).

Args:
items: Overload items matching the actual arguments arg_types: Actual argument types arg_kinds: Actual argument kinds arg_names: Actual argument names
Parameters
items:List[CallableType]Undocumented
return​_types:List[Type]Undocumented
arg​_types:List[Type]Undocumented
arg​_kinds:List[ArgKind]Undocumented
arg​_names:Optional[Sequence[Optional[str]]]Undocumented
Returns
boolUndocumented
def arg_approximate_similarity(actual, formal): (source)

Return if caller argument (actual) is roughly compatible with signature arg (formal).

This function is deliberately loose and will report two types are similar as long as their "shapes" are plausibly the same.

This is useful when we're doing error reporting: for example, if we're trying to select an overload alternative and there's no exact match, we can use this function to help us identify which alternative the user might have meant to match.

Parameters
actual:TypeUndocumented
formal:TypeUndocumented
Returns
boolUndocumented
def extract_refexpr_names(expr): (source)

Recursively extracts all module references from a reference expression.

Note that currently, the only two subclasses of RefExpr are NameExpr and MemberExpr.

Parameters
expr:RefExprUndocumented
Returns
Set[str]Undocumented
def get_partial_instance_type(t): (source)

Undocumented

Parameters
t:Optional[Type]Undocumented
Returns
Optional[PartialType]Undocumented
def has_any_type(t, ignore_in_type_obj=False): (source)
Whether t contains an Any type
Parameters
t:TypeUndocumented
ignore​_in​_type​_obj:boolUndocumented
Returns
boolUndocumented
def has_bytes_component(typ, py2=False): (source)
Is this one of builtin byte types, or a union that contains it?
Parameters
typ:TypeUndocumented
py2:boolUndocumented
Returns
boolUndocumented
def has_coroutine_decorator(t): (source)
Whether t came from a function decorated with @coroutine.
Parameters
t:TypeUndocumented
Returns
boolUndocumented
def has_erased_component(t): (source)

Undocumented

Parameters
t:Optional[Type]Undocumented
Returns
boolUndocumented
def has_uninhabited_component(t): (source)

Undocumented

Parameters
t:Optional[Type]Undocumented
Returns
boolUndocumented
def is_async_def(t): (source)
Whether t came from a function defined using async def.
Parameters
t:TypeUndocumented
Returns
boolUndocumented
def is_duplicate_mapping(mapping, actual_types, actual_kinds): (source)

Undocumented

Parameters
mapping:List[int]Undocumented
actual​_types:List[Type]Undocumented
actual​_kinds:List[ArgKind]Undocumented
Returns
boolUndocumented
def is_expr_literal_type(node): (source)
Returns 'true' if the given node is a Literal
Parameters
node:ExpressionUndocumented
Returns
boolUndocumented
def is_non_empty_tuple(t): (source)

Undocumented

Parameters
t:TypeUndocumented
Returns
boolUndocumented
def is_operator_method(fullname): (source)

Undocumented

Parameters
fullname:Optional[str]Undocumented
Returns
boolUndocumented
def merge_typevars_in_callables_by_name(callables): (source)

Takes all the typevars present in the callables and 'combines' the ones with the same name.

For example, suppose we have two callables with signatures "f(x: T, y: S) -> T" and "f(x: List[Tuple[T, S]]) -> Tuple[T, S]". Both callables use typevars named "T" and "S", but we treat them as distinct, unrelated typevars. (E.g. they could both have distinct ids.)

If we pass in both callables into this function, it returns a list containing two new callables that are identical in signature, but use the same underlying TypeVarType for T and S.

This is useful if we want to take the output lists and "merge" them into one callable in some way -- for example, when unioning together overloads.

Returns both the new list of callables and a list of all distinct TypeVarType objects used.

Parameters
callables:Sequence[CallableType]Undocumented
Returns
Tuple[List[CallableType], List[TypeVarType]]Undocumented
def replace_callable_return_type(c, new_ret_type): (source)
Return a copy of a callable type with a different return type.
Parameters
c:CallableTypeUndocumented
new​_ret​_type:TypeUndocumented
Returns
CallableTypeUndocumented
def try_getting_literal(typ): (source)
If possible, get a more precise literal type for a given type.
Parameters
typ:TypeUndocumented
Returns
ProperTypeUndocumented
def type_info_from_type(typ): (source)
Gets the TypeInfo for a type, indirecting through things like type variables and tuples.
Parameters
typ:TypeUndocumented
Returns
Optional[TypeInfo]Undocumented
MAX_UNIONS: int = (source)

Undocumented

Value
5
OVERLAPPING_TYPES_ALLOWLIST: list[str] = (source)

Undocumented

Value
['builtins.set',
 'builtins.frozenset',
 'typing.KeysView',
 'typing.ItemsView',
 'builtins._dict_keys',
 'builtins._dict_items',
 '_collections_abc.dict_keys',
...
ArgChecker: _TypeAlias = (source)

Undocumented