module documentation

Calculation of the least upper bound types (joins).

Class InstanceJoiner Undocumented
Class TypeJoinVisitor Implementation of the least upper bound algorithm.
Function combine_arg_names Produces a list of argument names compatible with both callables.
Function combine_similar_callables Undocumented
Function is_better Undocumented
Function is_similar_callables Return True if t and s have identical numbers of arguments, default arguments and varargs.
Function join_similar_callables Undocumented
Function join_simple Return a simple least upper bound given the declared type.
Function join_type_list Undocumented
Function join_types Return the least upper bound of s and t.
Function normalize_callables Undocumented
Function object_from_instance Construct the type 'builtins.object' from an instance type.
Function object_or_any_from_type Undocumented
Function trivial_join Return one of types (expanded) if it is a supertype of other, otherwise top type.
Function unpack_callback_protocol Undocumented
def combine_arg_names(t: CallableType, s: CallableType) -> list[str|None]: (source)

Produces a list of argument names compatible with both callables. For example, suppose 't' and 's' have the following signatures: - t: (a: int, b: str, X: str) -> None - s: (a: int, b: str, Y: str) -> None This function would return ["a", "b", None]. This information is then used above to compute the join of t and s, which results in a signature of (a: int, b: str, str) -> None. Note that the third argument's name is omitted and 't' and 's' are both valid subtypes of this inferred signature. Precondition: is_similar_types(t, s) is true.

def combine_similar_callables(t: CallableType, s: CallableType) -> CallableType: (source)

Undocumented

def is_better(t: Type, s: Type) -> bool: (source)

Undocumented

def is_similar_callables(t: CallableType, s: CallableType) -> bool: (source)

Return True if t and s have identical numbers of arguments, default arguments and varargs.

def join_similar_callables(t: CallableType, s: CallableType) -> CallableType: (source)

Undocumented

def join_simple(declaration: Type|None, s: Type, t: Type) -> ProperType: (source)

Return a simple least upper bound given the declared type. This function should be only used by binder, and should not recurse. For all other uses, use `join_types()`.

def join_type_list(types: list[Type]) -> Type: (source)

Undocumented

@overload
def join_types(s: ProperType, t: ProperType, instance_joiner: InstanceJoiner|None = None) -> ProperType:
@overload
def join_types(s: Type, t: Type, instance_joiner: InstanceJoiner|None = None) -> Type:
(source)

Return the least upper bound of s and t. For example, the join of 'int' and 'object' is 'object'.

def normalize_callables(s: ProperType, t: ProperType) -> tuple[ProperType, ProperType]: (source)

Undocumented

def object_from_instance(instance: Instance) -> Instance: (source)

Construct the type 'builtins.object' from an instance type.

def object_or_any_from_type(typ: ProperType) -> ProperType: (source)

Undocumented

def trivial_join(s: Type, t: Type) -> Type: (source)

Return one of types (expanded) if it is a supertype of other, otherwise top type.

def unpack_callback_protocol(t: Instance) -> ProperType|None: (source)

Undocumented