module documentation
(source)

Type inference constraints.
Class ​Complete​Type​Visitor Undocumented
Class ​Constraint A representation of a type constraint.
Class ​Constraint​Builder​Visitor Visitor class for inferring type constraints.
Function any​_constraints Deduce what we can from a collection of constraint lists.
Function find​_matching​_overload​_item Disambiguate overload item against a template.
Function infer​_constraints Infer type constraints.
Function infer​_constraints​_for​_callable Infer type variable constraints for a callable and actual arguments.
Function infer​_constraints​_if​_possible No summary
Function is​_complete​_type Is a type complete?
Function is​_same​_constraint Undocumented
Function is​_same​_constraints Undocumented
Function is​_similar​_constraints Check that two lists of constraints have similar structure.
Function merge​_with​_any Transform a constraint target into a union with given Any type.
Function neg​_op Map SubtypeOf to SupertypeOf and vice versa.
Function select​_trivial Select only those lists where each item is a constraint against Any.
Function simplify​_away​_incomplete​_types Undocumented
Constant SUBTYPE​_OF Undocumented
Constant SUPERTYPE​_OF Undocumented
Function _infer​_constraints Undocumented
Function _is​_similar​_constraints Check that every constraint in the first list has a similar one in the second.
def any_constraints(options, eager): (source)

Deduce what we can from a collection of constraint lists.

It's a given that at least one of the lists must be satisfied. A None element in the list of options represents an unsatisfiable constraint and is ignored. Ignore empty constraint lists if eager is true -- they are always trivially satisfiable.

Parameters
options:List[Optional[List[Constraint]]]Undocumented
eager:boolUndocumented
Returns
List[Constraint]Undocumented
def find_matching_overload_item(overloaded, template): (source)
Disambiguate overload item against a template.
Parameters
overloaded:OverloadedUndocumented
template:CallableTypeUndocumented
Returns
CallableTypeUndocumented
def infer_constraints(template, actual, direction): (source)

Infer type constraints.

Match a template type, which may contain type variable references, recursively against a type which does not contain (the same) type variable references. The result is a list of type constrains of form 'T is a supertype/subtype of x', where T is a type variable present in the template and x is a type without reference to type variables present in the template.

Assume T and S are type variables. Now the following results can be calculated (read as '(template, actual) --> result'):

(T, X) --> T :> X (X[T], X[Y]) --> T <: Y and T :> Y ((T, T), (X, Y)) --> T :> X and T :> Y ((T, S), (X, Y)) --> T :> X and S :> Y (X[T], Any) --> T <: Any and T :> Any

The constraints are represented as Constraint objects.

Parameters
template:TypeUndocumented
actual:TypeUndocumented
direction:intUndocumented
Returns
List[Constraint]Undocumented
def infer_constraints_for_callable(callee, arg_types, arg_kinds, formal_to_actual, context): (source)

Infer type variable constraints for a callable and actual arguments.

Return a list of constraints.

Parameters
callee:CallableTypeUndocumented
arg​_types:Sequence[Optional[Type]]Undocumented
arg​_kinds:List[ArgKind]Undocumented
formal​_to​_actual:List[List[int]]Undocumented
context:ArgumentInferContextUndocumented
Returns
List[Constraint]Undocumented
def infer_constraints_if_possible(template, actual, direction): (source)
Like infer_constraints, but return None if the input relation is known to be unsatisfiable, for example if template=List[T] and actual=int. (In this case infer_constraints would return [], just like it would for an automatically satisfied relation like template=List[T] and actual=object.)
Parameters
template:TypeUndocumented
actual:TypeUndocumented
direction:intUndocumented
Returns
Optional[List[Constraint]]Undocumented
def is_complete_type(typ): (source)

Is a type complete?

A complete doesn't have uninhabited type components or (when not in strict optional mode) None components.

Parameters
typ:TypeUndocumented
Returns
boolUndocumented
def is_same_constraint(c1, c2): (source)

Undocumented

Parameters
c1:ConstraintUndocumented
c2:ConstraintUndocumented
Returns
boolUndocumented
def is_same_constraints(x, y): (source)

Undocumented

Parameters
x:List[Constraint]Undocumented
y:List[Constraint]Undocumented
Returns
boolUndocumented
def is_similar_constraints(x, y): (source)

Check that two lists of constraints have similar structure.

This means that each list has same type variable plus direction pairs (i.e we ignore the target). Except for constraints where target is Any type, there we ignore direction as well.

Parameters
x:List[Constraint]Undocumented
y:List[Constraint]Undocumented
Returns
boolUndocumented
def merge_with_any(constraint): (source)
Transform a constraint target into a union with given Any type.
Parameters
constraint:ConstraintUndocumented
Returns
ConstraintUndocumented
def neg_op(op): (source)
Map SubtypeOf to SupertypeOf and vice versa.
Parameters
op:intUndocumented
Returns
intUndocumented
def select_trivial(options): (source)
Select only those lists where each item is a constraint against Any.
Parameters
options:Sequence[Optional[List[Constraint]]]Undocumented
Returns
List[List[Constraint]]Undocumented
def simplify_away_incomplete_types(types): (source)

Undocumented

Parameters
types:Iterable[Type]Undocumented
Returns
List[Type]Undocumented
SUBTYPE_OF: int = (source)

Undocumented

Value
0
SUPERTYPE_OF: int = (source)

Undocumented

Value
1
def _infer_constraints(template, actual, direction): (source)

Undocumented

Parameters
template:TypeUndocumented
actual:TypeUndocumented
direction:intUndocumented
Returns
List[Constraint]Undocumented
def _is_similar_constraints(x, y): (source)

Check that every constraint in the first list has a similar one in the second.

See docstring above for definition of similarity.

Parameters
x:List[Constraint]Undocumented
y:List[Constraint]Undocumented
Returns
boolUndocumented