Skip to content

Commit 1903402

Browse files
committed
Undo style change to make it easier to review, feel free to add in separate PR
1 parent 786fb55 commit 1903402

File tree

1 file changed

+26
-40
lines changed

1 file changed

+26
-40
lines changed

mypy/checkexpr.py

Lines changed: 26 additions & 40 deletions
Original file line numberDiff line numberDiff line change
@@ -1727,9 +1727,33 @@ def check_callable_call(
17271727
callee = callee.copy_modified(ret_type=fresh_ret_type)
17281728

17291729
if callee.is_generic():
1730-
callee, formal_to_actual = self.adjust_generic_callable_params_mapping(
1731-
callee, args, arg_kinds, arg_names, formal_to_actual, context
1730+
need_refresh = any(
1731+
isinstance(v, (ParamSpecType, TypeVarTupleType)) for v in callee.variables
17321732
)
1733+
callee = freshen_function_type_vars(callee)
1734+
callee = self.infer_function_type_arguments_using_context(callee, context)
1735+
if need_refresh:
1736+
# Argument kinds etc. may have changed due to
1737+
# ParamSpec or TypeVarTuple variables being replaced with an arbitrary
1738+
# number of arguments; recalculate actual-to-formal map
1739+
formal_to_actual = map_actuals_to_formals(
1740+
arg_kinds,
1741+
arg_names,
1742+
callee.arg_kinds,
1743+
callee.arg_names,
1744+
lambda i: self.accept(args[i]),
1745+
)
1746+
callee = self.infer_function_type_arguments(
1747+
callee, args, arg_kinds, arg_names, formal_to_actual, need_refresh, context
1748+
)
1749+
if need_refresh:
1750+
formal_to_actual = map_actuals_to_formals(
1751+
arg_kinds,
1752+
arg_names,
1753+
callee.arg_kinds,
1754+
callee.arg_names,
1755+
lambda i: self.accept(args[i]),
1756+
)
17331757

17341758
param_spec = callee.param_spec()
17351759
if (
@@ -2737,44 +2761,6 @@ def check_overload_call(
27372761
self.chk.fail(message_registry.TOO_MANY_UNION_COMBINATIONS, context)
27382762
return result
27392763

2740-
def adjust_generic_callable_params_mapping(
2741-
self,
2742-
callee: CallableType,
2743-
args: list[Expression],
2744-
arg_kinds: list[ArgKind],
2745-
arg_names: Sequence[str | None] | None,
2746-
formal_to_actual: list[list[int]],
2747-
context: Context,
2748-
) -> tuple[CallableType, list[list[int]]]:
2749-
need_refresh = any(
2750-
isinstance(v, (ParamSpecType, TypeVarTupleType)) for v in callee.variables
2751-
)
2752-
callee = freshen_function_type_vars(callee)
2753-
callee = self.infer_function_type_arguments_using_context(callee, context)
2754-
if need_refresh:
2755-
# Argument kinds etc. may have changed due to
2756-
# ParamSpec or TypeVarTuple variables being replaced with an arbitrary
2757-
# number of arguments; recalculate actual-to-formal map
2758-
formal_to_actual = map_actuals_to_formals(
2759-
arg_kinds,
2760-
arg_names,
2761-
callee.arg_kinds,
2762-
callee.arg_names,
2763-
lambda i: self.accept(args[i]),
2764-
)
2765-
callee = self.infer_function_type_arguments(
2766-
callee, args, arg_kinds, arg_names, formal_to_actual, need_refresh, context
2767-
)
2768-
if need_refresh:
2769-
formal_to_actual = map_actuals_to_formals(
2770-
arg_kinds,
2771-
arg_names,
2772-
callee.arg_kinds,
2773-
callee.arg_names,
2774-
lambda i: self.accept(args[i]),
2775-
)
2776-
return callee, formal_to_actual
2777-
27782764
def plausible_overload_call_targets(
27792765
self,
27802766
arg_types: list[Type],

0 commit comments

Comments
 (0)