Undocumented
Class |
|
Undocumented |
Function | adjust |
Find out if `left` is a Tuple[A, ...], and adjust its length to `right` |
Function | are |
Returns true if left and right are overlapping tuples. |
Function | are |
Returns 'true' if left and right are overlapping TypeDictTypes. |
Function | get |
This function takes any "Union-like" type and returns a list of the available "options". |
Function | is |
Return True if x is an Enum, and y is an Union with at least one Literal from x |
Function | is |
Return True if x is a Literal and y is an Union that includes x |
Function | is |
The same as 'is_overlapping_erased_types', except the types are erased first. |
Function | is |
Can a value of type 'left' also be of type 'right' or vice-versa? |
Function | is |
Undocumented |
Function | meet |
Undocumented |
Function | meet |
Undocumented |
Function | meet |
Return the greatest lower bound of two types. |
Function | narrow |
Return the declared type narrowed down to another type. |
Function | trivial |
Return one of types (expanded) if it is a subtype of other, otherwise bottom type. |
Function | typed |
Check if a TypedDict type is overlapping with a Mapping. |
Function | typed |
Is this a pair where one type is a TypedDict and another one is an instance of Mapping? |
Type
, right: Type
, *, ignore_promotions: bool
= False, prohibit_none_typevar_overlap: bool
= False) -> bool
:
(source)
¶
Returns true if left and right are overlapping tuples.
TypedDictType
, right: TypedDictType
, *, ignore_promotions: bool
= False, prohibit_none_typevar_overlap: bool
= False) -> bool
:
(source)
¶
Returns 'true' if left and right are overlapping TypeDictTypes.
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": - Unions - TypeVars with value restrictions - Overloads 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 current exceptions are regular TypeVars and ParamSpecs. For these "TypeVarLike"s, we return a list containing that TypeVarLike'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.
Type
, right: Type
, *, ignore_promotions: bool
= False) -> bool
:
(source)
¶
The same as 'is_overlapping_erased_types', except the types are erased first.
Type
, right: Type
, ignore_promotions: bool
= False, prohibit_none_typevar_overlap: bool
= False, ignore_uninhabited: bool
= False) -> bool
:
(source)
¶
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).
Type
, right: Type
, overlapping: Callable[ [ Type, Type], bool]
) -> bool
:
(source)
¶
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: - TypedDict(x=int, y=str) overlaps with Dict[str, Union[str, int]] - TypedDict(x=int, y=str) doesn't overlap with Dict[str, int] 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: - TypedDict(x=str, y=str, total=False) overlaps with Dict[str, str] - TypedDict(x=str, y=str, total=False) doesn't overlap with Dict[str, int] - TypedDict(x=int, y=str, total=False) overlaps with Dict[str, str] 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.
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.