예제 #1
0
파일: infer.py 프로젝트: ChaiYuanUMN/mypy
def infer_function_type_arguments(callee_type: CallableType,
                                  arg_types: List[Optional[Type]],
                                  arg_kinds: List[int],
                                  formal_to_actual: List[List[int]],
                                  strict: bool = True) -> List[Type]:
    """Infer the type arguments of a generic function.

    Return an array of lower bound types for the type variables -1 (at
    index 0), -2 (at index 1), etc. A lower bound is None if a value
    could not be inferred.

    Arguments:
      callee_type: the target generic function
      arg_types: argument types at the call site (each optional; if None,
                 we are not considering this argument in the current pass)
      arg_kinds: nodes.ARG_* values for arg_types
      formal_to_actual: mapping from formal to actual variable indices
    """
    # Infer constraints.
    constraints = infer_constraints_for_callable(
        callee_type, arg_types, arg_kinds, formal_to_actual)

    # Solve constraints.
    type_vars = callee_type.type_var_ids()
    return solve_constraints(type_vars, constraints, strict)
예제 #2
0
def infer_function_type_arguments(callee_type: CallableType,
                                  arg_types: List[Optional[Type]],
                                  arg_kinds: List[int],
                                  formal_to_actual: List[List[int]],
                                  strict: bool = True) -> List[Type]:
    """Infer the type arguments of a generic function.

    Return an array of lower bound types for the type variables -1 (at
    index 0), -2 (at index 1), etc. A lower bound is None if a value
    could not be inferred.

    Arguments:
      callee_type: the target generic function
      arg_types: argument types at the call site (each optional; if None,
                 we are not considering this argument in the current pass)
      arg_kinds: nodes.ARG_* values for arg_types
      formal_to_actual: mapping from formal to actual variable indices
    """
    # Infer constraints.
    constraints = infer_constraints_for_callable(callee_type, arg_types,
                                                 arg_kinds, formal_to_actual)

    # Solve constraints.
    type_vars = callee_type.type_var_ids()
    return solve_constraints(type_vars, constraints, strict)
예제 #3
0
def infer_type_arguments(type_var_ids: List[int],
                         template: Type, actual: Type,
                         basic: BasicTypes) -> List[Type]:
    # Like infer_function_type_arguments, but only match a single type
    # against a generic type.
    constraints = infer_constraints(template, actual, SUBTYPE_OF)
    return solve_constraints(type_var_ids, constraints, basic)
예제 #4
0
def infer_function_type_arguments(callee_type: Callable,
                                  arg_types: List[Type],
                                  arg_kinds: List[int],
                                  formal_to_actual: List[List[int]],
                                  basic: BasicTypes) -> List[Type]:
    """Infer the type arguments of a generic function.

    Return an array of lower bound types for the type variables -1 (at
    index 0), -2 (at index 1), etc. A lower bound is None if a value
    could not be inferred.

    Arguments:
      callee_type: the target generic function
      arg_types: argument types at the call site
      arg_kinds: nodes.ARG_* values for arg_types
      formal_to_actual: mapping from formal to actual variable indices
      basic: references to basic types which are needed during inference
    """
    # Infer constraints.
    constraints = infer_constraints_for_callable(
        callee_type, arg_types, arg_kinds, formal_to_actual)

    # Solve constraints.
    type_vars = callee_type.type_var_ids()
    return solve_constraints(type_vars, constraints, basic)
예제 #5
0
파일: infer.py 프로젝트: rondan100/tkinter
def infer_type_arguments(type_var_ids: List[TypeVarId],
                         template: Type, actual: Type,
                         is_supertype: bool = False) -> List[Optional[Type]]:
    # Like infer_function_type_arguments, but only match a single type
    # against a generic type.
    constraints = infer_constraints(template, actual,
                                    SUPERTYPE_OF if is_supertype else SUBTYPE_OF)
    return solve_constraints(type_var_ids, constraints)
예제 #6
0
 def assert_solve(self, vars, constraints, results):
     res = []
     for r in results:
         if isinstance(r, tuple):
             res.append(r[0])
         else:
             res.append(r)
     actual = solve_constraints(vars, constraints)
     assert_equal(str(actual), str(res))
예제 #7
0
파일: testsolve.py 프로젝트: vnitinv/mypy
 def assert_solve(self, vars, constraints, results):
     res = []
     for r in results:
         if isinstance(r, tuple):
             res.append(r[0])
         else:
             res.append(r)
     actual = solve_constraints(vars, constraints)
     assert_equal(str(actual), str(res))
예제 #8
0
 def assert_solve(self,
                  vars: List[TypeVarId],
                  constraints: List[Constraint],
                  results: List[Union[Type, Tuple[Type, Type]]],
                  ) -> None:
     res = []
     for r in results:
         if isinstance(r, tuple):
             res.append(r[0])
         else:
             res.append(r)
     actual = solve_constraints(vars, constraints)
     assert_equal(str(actual), str(res))
예제 #9
0
 def assert_solve(self,
                  vars: List[TypeVarId],
                  constraints: List[Constraint],
                  results: List[Union[None, Type, Tuple[Type, Type]]],
                  ) -> None:
     res = []  # type: List[Optional[Type]]
     for r in results:
         if isinstance(r, tuple):
             res.append(r[0])
         else:
             res.append(r)
     actual = solve_constraints(vars, constraints)
     assert_equal(str(actual), str(res))
예제 #10
0
파일: infer.py 프로젝트: SRiikonen/mypy
                                    BasicTypes basic):
    """Infer the type arguments of a generic function.

    Return an array of lower bound types for the type variables -1 (at
    index 0), -2 (at index 1), etc. A lower bound is None if a value
    could not be inferred.

    Arguments:
      callee_type: the target generic function
      arg_types: argument types at the call site
      arg_kinds: nodes.ARG_* values for arg_types
      formal_to_actual: mapping from formal to actual variable indices
      basic: references to basic types which are needed during inference
    """
    # Infer constraints.
    constraints = infer_constraints_for_callable(
        callee_type, arg_types, arg_kinds, formal_to_actual)
    
    # Solve constraints.
    type_vars = callee_type.type_var_ids()
    return solve_constraints(type_vars, constraints, basic)


Type[] infer_type_arguments(int[] type_var_ids,
                               Type template, Type actual,
                               BasicTypes basic):
    # Like infer_function_type_arguments, but only match a single type
    # against a generic type.
    constraints = infer_constraints(template, actual, SUBTYPE_OF)
    return solve_constraints(type_var_ids, constraints, basic)
예제 #11
0
파일: infer.py 프로젝트: SRiikonen/mypy-py
def infer_type_arguments(type_var_ids, template, actual, basic):
    # Like infer_function_type_arguments, but only match a single type
    # against a generic type.
    constraints = infer_constraints(template, actual, SUBTYPE_OF)
    return solve_constraints(type_var_ids, constraints, basic)