Skip to content

Commit d77d4bd

Browse files
authored
Attempt 2
1 parent 90f420f commit d77d4bd

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
@@ -585,7 +585,7 @@ def check_overlapping_overloads(self, defn: OverloadedFuncDef) -> None:
585585
# This is to match the direction the implementation's return
586586
# needs to be compatible in.
587587
if impl_type.variables:
588-
impl = unify_generic_callable(sig1, impl_type,
588+
impl = unify_generic_callable(impl_type, sig1,
589589
ignore_return=False,
590590
return_constraint_direction=SUPERTYPE_OF)
591591
if impl is None:

mypy/subtypes.py

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

12001200
constraints: List[mypy.constraints.Constraint] = []
1201-
for arg_type, target_arg_type in zip(type.arg_types, target.arg_types):
1202-
c = mypy.constraints.infer_constraints(
1203-
arg_type, target_arg_type, mypy.constraints.SUPERTYPE_OF)
1204-
constraints.extend(c)
1201+
# check by names
1202+
argument_names_map = {}
1203+
# `is_unsafe_overlapping_overload_signatures` calls this both ways
1204+
for i in range(len(target.arg_types)):
1205+
if target.arg_names[i]:
1206+
argument_names_map[target.arg_names[i]] = target.arg_types[i]
1207+
for i in range(len(type.arg_types)):
1208+
if type.arg_names[i]:
1209+
argument_names_map[type.arg_names[i]] = type.arg_types[i]
1210+
for i in range(len(target.arg_types)):
1211+
if target.arg_names[i]:
1212+
c = mypy.constraints.infer_constraints(
1213+
argument_names_map[target.arg_names[i]], target.arg_types[i], mypy.constraints.SUPERTYPE_OF)
1214+
constraints.extend(c)
1215+
# check pos-only arguments
1216+
for arg, target_arg in zip(type.formal_arguments(), target.formal_arguments()):
1217+
if arg.pos and target_arg.pos:
1218+
c = mypy.constraints.infer_constraints(
1219+
arg.type, target_arg.type, mypy.constraints.SUPERTYPE_OF)
1220+
constraints.extend(c)
1221+
else:
1222+
# optimization, no more positional arguments
1223+
break
12051224
if not ignore_return:
12061225
c = mypy.constraints.infer_constraints(
12071226
type.ret_type, target.ret_type, return_constraint_direction)

0 commit comments

Comments
 (0)