Undocumented
Class | TypeMeetVisitor |
Undocumented |
Function | adjust_tuple |
Find out if left is a Tuple[A, ...], and adjust its length to right |
Function | are_tuples_overlapping |
Returns true if left and right are overlapping tuples. |
Function | are_typed_dicts_overlapping |
Returns 'true' if left and right are overlapping TypeDictTypes. |
Function | get_possible_variants |
This function takes any "Union-like" type and returns a list of the available "options". |
Function | is_overlapping_erased_types |
The same as 'is_overlapping_erased_types', except the types are erased first. |
Function | is_overlapping_types |
Can a value of type 'left' also be of type 'right' or vice-versa? |
Function | is_tuple |
Undocumented |
Function | meet_similar_callables |
Undocumented |
Function | meet_type_list |
Undocumented |
Function | meet_types |
Return the greatest lower bound of two types. |
Function | narrow_declared_type |
Return the declared type narrowed down to another type. |
Function | trivial_meet |
Return one of types (expanded) if it is a subtype of other, otherwise bottom type. |
Function | typed_dict_mapping_overlap |
Check if a TypedDict type is overlapping with a Mapping. |
Function | typed_dict_mapping_pair |
Is this a pair where one type is a TypedDict and another one is an instance of Mapping? |
left
is a Tuple[A, ...], and adjust its length to right
Parameters | |
left:ProperType | Undocumented |
r:ProperType | Undocumented |
Returns | |
Optional[ | Undocumented |
Parameters | |
left:TypedDictType | Undocumented |
right:TypedDictType | Undocumented |
ignore_promotions:bool | Undocumented |
prohibit_none_typevar_overlap:bool | Undocumented |
Returns | |
bool | Undocumented |
This function takes any "Union-like" type and returns a list of the available "options".
Specifically, there are currently exactly three different types that can have "variants" or are "union-like":
This function will return a list of each "option" present in those types.
If this function receives any other type, we return a list containing just that original type. (E.g. pretend the type was contained within a singleton union).
The only exception is regular TypeVars: we return a list containing that TypeVar's upper bound.
This function is useful primarily when checking to see if two types are overlapping: the algorithm to check if two unions are overlapping is fundamentally the same as the algorithm for checking if two overloads are overlapping.
Normalizing both kinds of types in the same way lets us reuse the same algorithm for both.
Parameters | |
typ:Type | Undocumented |
Returns | |
List[ | Undocumented |
Can a value of type 'left' also be of type 'right' or vice-versa?
If 'ignore_promotions' is True, we ignore promotions while checking for overlaps. If 'prohibit_none_typevar_overlap' is True, we disallow None from overlapping with TypeVars (in both strict-optional and non-strict-optional mode).
Parameters | |
left:Type | Undocumented |
right:Type | Undocumented |
ignore_promotions:bool | Undocumented |
prohibit_none_typevar_overlap:bool | Undocumented |
Returns | |
bool | Undocumented |
Undocumented
Parameters | |
t:CallableType | Undocumented |
s:CallableType | Undocumented |
Returns | |
CallableType | Undocumented |
Parameters | |
s:Type | Undocumented |
t:Type | Undocumented |
Returns | |
ProperType | Undocumented |
Parameters | |
s:Type | Undocumented |
t:Type | Undocumented |
Returns | |
ProperType | Undocumented |
Check if a TypedDict type is overlapping with a Mapping.
The basic logic here consists of two rules:
A TypedDict with some required keys is overlapping with Mapping[str, <some type>] if and only if every key type is overlapping with <some type>. For example:
Note that any additional non-required keys can't change the above result.
A TypedDict with no required keys overlaps with Mapping[str, <some type>] if and only if at least one of key types overlaps with <some type>. For example:
As usual empty, dictionaries lie in a gray area. In general, List[str] and List[str] are considered non-overlapping despite empty list belongs to both. However, List[int] and List[<nothing>] are considered overlapping.
So here we follow the same logic: a TypedDict with no required keys is considered non-overlapping with Mapping[str, <some type>], but is considered overlapping with Mapping[<nothing>, <nothing>]. This way we avoid false positives for overloads, and also avoid false positives for comparisons like SomeTypedDict == {} under --strict-equality.
Parameters | |
left:Type | Undocumented |
right:Type | Undocumented |
overlapping:Callable[ | Undocumented |
Returns | |
bool | Undocumented |
Is this a pair where one type is a TypedDict and another one is an instance of Mapping?
This case requires a precise/principled consideration because there are two use cases that push the boundary the opposite ways: we need to avoid spurious overlaps to avoid false positives for overloads, but we also need to avoid spuriously non-overlapping types to avoid false positives with --strict-equality.
Parameters | |
left:Type | Undocumented |
right:Type | Undocumented |
Returns | |
bool | Undocumented |