Skip to content

Commit 56d988f

Browse files
committed
Attempt 2
1 parent bf3a63e commit 56d988f

File tree

2 files changed

+24
-5
lines changed

2 files changed

+24
-5
lines changed

mypy/checker.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -560,7 +560,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
560560
# This is to match the direction the implementation's return
561561
# needs to be compatible in.
562562
if impl_type.variables:
563-
impl = unify_generic_callable(sig1, impl_type,
563+
impl = unify_generic_callable(impl_type, sig1,
564564
ignore_return=False,
565565
return_constraint_direction=SUPERTYPE_OF)
566566
if impl is None:

mypy/subtypes.py

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1115,10 +1115,29 @@ def unify_generic_callable(type: CallableType, target: CallableType,
11151115
return_constraint_direction = mypy.constraints.SUBTYPE_OF
11161116

11171117
constraints: List[mypy.constraints.Constraint] = []
1118-
for arg_type, target_arg_type in zip(type.arg_types, target.arg_types):
1119-
c = mypy.constraints.infer_constraints(
1120-
arg_type, target_arg_type, mypy.constraints.SUPERTYPE_OF)
1121-
constraints.extend(c)
1118+
# check by names
1119+
argument_names_map = {}
1120+
# `is_unsafe_overlapping_overload_signatures` calls this both ways
1121+
for i in range(len(target.arg_types)):
1122+
if target.arg_names[i]:
1123+
argument_names_map[target.arg_names[i]] = target.arg_types[i]
1124+
for i in range(len(type.arg_types)):
1125+
if type.arg_names[i]:
1126+
argument_names_map[type.arg_names[i]] = type.arg_types[i]
1127+
for i in range(len(target.arg_types)):
1128+
if target.arg_names[i]:
1129+
c = mypy.constraints.infer_constraints(
1130+
argument_names_map[target.arg_names[i]], target.arg_types[i], mypy.constraints.SUPERTYPE_OF)
1131+
constraints.extend(c)
1132+
# check pos-only arguments
1133+
for arg, target_arg in zip(type.formal_arguments(), target.formal_arguments()):
1134+
if arg.pos and target_arg.pos:
1135+
c = mypy.constraints.infer_constraints(
1136+
arg.type, target_arg.type, mypy.constraints.SUPERTYPE_OF)
1137+
constraints.extend(c)
1138+
else:
1139+
# optimization, no more positional arguments
1140+
break
11221141
if not ignore_return:
11231142
c = mypy.constraints.infer_constraints(
11241143
type.ret_type, target.ret_type, return_constraint_direction)

0 commit comments

Comments
 (0)