Undocumented
| Class | |
Undocumented |
| Class | |
A domain of instantiated type variables. |
| Function | approximate |
Undocumented |
| Function | better |
Get a signature from the function def information wrapped by this type instance. Return None if there is no function wrapped, in the case of a written 'Callable' annotation for instance. |
| Function | bind |
Dertemine signature based compatibility between two callables. Returns (caller, callee, bound arguments). |
| Function | callable |
Returns tuple: (args, kwargs, rtype) |
| Function | debug |
Undocumented |
| Function | merge |
When two possible values for a given type variable doesn't unify, we use the first common - nominal - supertype, that's not object, or fail. |
| Function | occurs |
Checks whether a types variable occurs in any other types. |
| Function | occurs |
Checks whether a type variable occurs in a type expression. |
| Function | poor |
Get a approximated signature based on a Callable type (created from annotations or from ast.Call before unification). |
| Function | substitute |
Undocumented |
| Function | unify |
Unify the two types t1 and t2. |
Get a signature from the function def information wrapped by this type instance. Return None if there is no function wrapped, in the case of a written 'Callable' annotation for instance.
Dertemine signature based compatibility between two callables. Returns (caller, callee, bound arguments).
Type) -> tuple[ Sequence[ Type], Mapping[ str, Type], Type]:
(source)
¶
Returns tuple: (args, kwargs, rtype)
When two possible values for a given type variable doesn't unify,
we use the first common - nominal - supertype, that's not object, or fail.
So list[str] and set[str] will be reconcile to Collection[str]. But None and int can't reconcile.
Checks whether a types variable occurs in any other types.
- Args:
- t: The TypeVariable to be tested for types: The sequence of types in which to search
- Returns:
- True if t occurs in any of types, otherwise False
Checks whether a type variable occurs in a type expression.
Note: Must be called with v pre-pruned
- Args:
- v: The TypeVariable to be tested for type2: The type in which to search
- Returns:
- True if v occurs in type2, otherwise False
Get a approximated signature based on a Callable type (created from annotations or from ast.Call before unification).
Unify the two types t1 and t2.
Returns a new type that represent the unification of both type.
- Args:
- t1: The first type to be made equivalent t2: The second type to be be equivalent subst: type variables substitutions.
- Returns:
- Tuple: (The unified type, Subst)
- Raises:
- InferenceError: Raised if the types cannot be unified.
>>> t = Type.overload.add_args(args= ... [Type.Callable.add_args([Type('float', 'builtins'), Type('int', 'builtins'),]), ... Type.Callable.add_args([Type.Union.add_args([Type('str', 'builtins'), ... Type('bytes', 'builtins'), ... Type('object', 'builtins')]), ... Type('str', 'builtins'),])]) >>> expr1 = Type.Callable.add_args([Type('int', 'builtins'), TypeVariable()]) >>> print(t.annotation) (float) -> int | (str | bytes | object) -> str >>> print(expr1.annotation) (int) -> @TypeVar... >>> print(unify(expr1, t).annotation) (float) -> int >>> expr2 = Type.Callable.add_args([Type('float', 'builtins'), TypeVariable()]) >>> print(unify(expr2, t).annotation) (float) -> int >>> expr3 = Type.Callable.add_args([Type('bytes', 'builtins'), TypeVariable()]) >>> print(unify(expr3, t).annotation) (object) -> str >>> t2 = Type.Callable.add_args([Type('list', 'builtins').add_args( ... [Type('@TypeVar1')]), Type('list', 'builtins').add_args( ... [Type('@TypeVar1')]),]) >>> expr4 = Type.Callable.add_args([Type('list', 'builtins').add_args([Type('float', 'builtins')]), Type('@TypeVar2')]) >>> s = Substitutions() >>> print(unify(expr4, t2, s).annotation) (list[float]) -> list[float]