Undocumented
Class |
|
Undocumented |
Class |
|
Undocumented |
Function | are |
Undocumented |
Function | are |
Helper function for is_callable_compatible, used for Parameter compatibility |
Function | are |
Undocumented |
Function | check |
Undocumented |
Function | covers |
Will isinstance(item, supertype) always return True at runtime? |
Function | find |
Find the type of member by 'name' in 'itype's TypeInfo. |
Function | find |
Find type of a variable or method 'node' (maybe also a decorated method). Apply type arguments from 'itype', and bind 'self' to 'subtype'. |
Function | flip |
Undocumented |
Function | get |
Detect whether a member 'name' is settable, whether it is an instance or class variable, and whether it is class or static method. |
Function | is |
Is the left compatible with the right, using the provided compatibility check? |
Function | is |
Undocumented |
Function | is |
Check if left is a more precise type than right. |
Function | is |
Is left a proper subtype of right? |
Function | is |
Check whether 'left' implements the protocol 'right'. |
Function | is |
Are these types proper subtypes of each other? |
Function | is |
Is 'left' subtype of 'right'? |
Function | non |
Find all non-callable members of a protocol. |
Function | pop |
Undocumented |
Function | restrict |
Return t minus s for runtime type assertions. |
Function | try |
Return the items of t, excluding any occurrence of s, if and only if - t only contains simple literals - s is a simple literal |
Function | unify |
Try to unify a generic callable type with another callable type. |
Constant | IS |
Undocumented |
Constant | IS |
Undocumented |
Constant | IS |
Undocumented |
Constant | IS |
Undocumented |
Type Variable | T |
Undocumented |
Type Alias |
|
Undocumented |
Function | _is |
Undocumented |
FormalArgument
, right: FormalArgument
, ignore_pos_arg_names: bool
, allow_partial_overlap: bool
, is_compat: Callable[ [ Type, Type], bool]
) -> bool
:
(source)
¶
Undocumented
Parameters|NormalizedCallableType
, right: Parameters|NormalizedCallableType
, *, is_compat: Callable[ [ Type, Type], bool]
, ignore_pos_arg_names: bool
= False, check_args_covariantly: bool
= False, allow_partial_overlap: bool
= False, strict_concatenate_check: bool
= True) -> bool
:
(source)
¶
Helper function for is_callable_compatible, used for Parameter compatibility
Type
, right: Type
, variance: int
, proper_subtype: bool
, subtype_context: SubtypeContext
) -> bool
:
(source)
¶
Undocumented
str
, itype: Instance
, subtype: Type
, is_operator: bool
= False, class_obj: bool
= False) -> Type|None
:
(source)
¶
Find the type of member by 'name' in 'itype's TypeInfo. Find the member type after applying type arguments from 'itype', and binding 'self' to 'subtype'. Return None if member was not found.
Var|FuncBase
, itype: Instance
, subtype: Type
, class_obj: bool
= False) -> Type
:
(source)
¶
Find type of a variable or method 'node' (maybe also a decorated method). Apply type arguments from 'itype', and bind 'self' to 'subtype'.
Callable[ [ Type, Type], bool]
) -> Callable[ [ Type, Type], bool]
:
(source)
¶
Undocumented
Detect whether a member 'name' is settable, whether it is an instance or class variable, and whether it is class or static method. The flags are defined as following: * IS_SETTABLE: whether this attribute can be set, not set for methods and non-settable properties; * IS_CLASSVAR: set if the variable is annotated as 'x: ClassVar[t]'; * IS_CLASS_OR_STATIC: set for methods decorated with @classmethod or with @staticmethod.
CallableType
, right: CallableType
, *, is_compat: Callable[ [ Type, Type], bool]
, is_compat_return: Callable[ [ Type, Type], bool]|None
= None, ignore_return: bool
= False, ignore_pos_arg_names: bool
= False, check_args_covariantly: bool
= False, allow_partial_overlap: bool
= False, strict_concatenate: bool
= False) -> bool
:
(source)
¶
Is the left compatible with the right, using the provided compatibility check? is_compat: The check we want to run against the parameters. is_compat_return: The check we want to run against the return type. If None, use the 'is_compat' check. check_args_covariantly: If true, check if the left's args is compatible with the right's instead of the other way around (contravariantly). This function is mostly used to check if the left is a subtype of the right which is why the default is to check the args contravariantly. However, it's occasionally useful to check the args using some other check, so we leave the variance configurable. For example, when checking the validity of overloads, it's useful to see if the first overload alternative has more precise arguments then the second. We would want to check the arguments covariantly in that case. Note! The following two function calls are NOT equivalent: is_callable_compatible(f, g, is_compat=is_subtype, check_args_covariantly=False) is_callable_compatible(g, f, is_compat=is_subtype, check_args_covariantly=True) The two calls are similar in that they both check the function arguments in the same direction: they both run `is_subtype(argument_from_g, argument_from_f)`. However, the two calls differ in which direction they check things like keyword arguments. For example, suppose f and g are defined like so: def f(x: int, *y: int) -> int: ... def g(x: int) -> int: ... In this case, the first call will succeed and the second will fail: f is a valid stand-in for g but not vice-versa. allow_partial_overlap: By default this function returns True if and only if *all* calls to left are also calls to right (with respect to the provided 'is_compat' function). If this parameter is set to 'True', we return True if *there exists at least one* call to left that's also a call to right. In other words, we perform an existential check instead of a universal one; we require left to only overlap with right instead of being a subset. For example, suppose we set 'is_compat' to some subtype check and compare following: f(x: float, y: str = "...", *args: bool) -> str g(*args: int) -> str This function would normally return 'False': f is not a subtype of g. However, we would return True if this parameter is set to 'True': the two calls are compatible if the user runs "f_or_g(3)". In the context of that specific call, the two functions effectively have signatures of: f2(float) -> str g2(int) -> str Here, f2 is a valid subtype of g2 so we return True. Specifically, if this parameter is set this function will: - Ignore optional arguments on either the left or right that have no corresponding match. - No longer mandate optional arguments on either side are also optional on the other. - No longer mandate that if right has a *arg or **kwarg that left must also have the same. Note: when this argument is set to True, this function becomes "symmetric" -- the following calls are equivalent: is_callable_compatible(f, g, is_compat=some_check, check_args_covariantly=False, allow_partial_overlap=True) is_callable_compatible(g, f, is_compat=some_check, check_args_covariantly=True, allow_partial_overlap=True) If the 'some_check' function is also symmetric, the two calls would be equivalent whether or not we check the args covariantly.
Type
, b: Type
, *, ignore_type_params: bool
= False, ignore_pos_arg_names: bool
= False, options: Options|None
= None, subtype_context: SubtypeContext|None
= None) -> bool
:
(source)
¶
Undocumented
Type
, right: Type
, *, ignore_promotions: bool
= False) -> bool
:
(source)
¶
Check if left is a more precise type than right. A left is a proper subtype of right, left is also more precise than right. Also, if right is Any, left is more precise than right, for any left.
Type
, right: Type
, *, subtype_context: SubtypeContext|None
= None, ignore_promotions: bool
= False, ignore_uninhabited: bool
= False, erase_instances: bool
= False, keep_erased_types: bool
= False) -> bool
:
(source)
¶
Is left a proper subtype of right? For proper subtypes, there's no need to rely on compatibility due to Any types. Every usable type is a proper subtype of itself. If erase_instances is True, erase left instance *after* mapping it to supertype (this is useful for runtime isinstance() checks). If keep_erased_types is True, do not consider ErasedType a subtype of all types (used by type inference against unions).
Instance
, right: Instance
, proper_subtype: bool
= False, class_obj: bool
= False, skip: list[ str]|None
= None) -> bool
:
(source)
¶
Check whether 'left' implements the protocol 'right'. If 'proper_subtype' is True, then check for a proper subtype. Treat recursive protocols by using the 'assuming' structural subtype matrix (in sparse representation, i.e. as a list of pairs (subtype, supertype)), see also comment in nodes.TypeInfo. When we enter a check for classes (A, P), defined as following:: class P(Protocol): def f(self) -> P: ... class A: def f(self) -> A: ... this results in A being a subtype of P without infinite recursion. On every false result, we pop the assumption, thus avoiding an infinite recursion as well.
Type
, b: Type
, ignore_promotions: bool
= True, subtype_context: SubtypeContext|None
= None) -> bool
:
(source)
¶
Are these types proper subtypes of each other? This means types may have different representation (e.g. an alias, or a non-simplified union) but are semantically exchangeable in all contexts.
Type
, right: Type
, *, subtype_context: SubtypeContext|None
= None, ignore_type_params: bool
= False, ignore_pos_arg_names: bool
= False, ignore_declared_variance: bool
= False, ignore_promotions: bool
= False, ignore_uninhabited: bool
= False, options: Options|None
= None) -> bool
:
(source)
¶
Is 'left' subtype of 'right'? Also consider Any to be a subtype of any type, and vice versa. This recursively applies to components of composite types (List[int] is subtype of List[Any], for example). type_parameter_checker is used to check the type parameters (for example, A with B in is_subtype(C[A], C[B]). The default checks for subtype relation between the type arguments (e.g., A and B), taking the variance of the type var into account.
def pop_on_exit(stack:
list[ tuple[ T, T]]
, left: T
, right: T
) -> Iterator[ None]
:
(source)
¶
Undocumented
Return t minus s for runtime type assertions. If we can't determine a precise result, return a supertype of the ideal result (just t is a valid result). This is used for type inference of runtime type checks such as isinstance(). Currently, this just removes elements of a union type.
Return the items of t, excluding any occurrence of s, if and only if - t only contains simple literals - s is a simple literal Otherwise, returns None
NormalizedCallableType
, target: NormalizedCallableType
, ignore_return: bool
, return_constraint_direction: int|None
= None) -> NormalizedCallableType|None
:
(source)
¶
Try to unify a generic callable type with another callable type. Return unified CallableType if successful; otherwise, return None.