@@ -1115,10 +1115,29 @@ def unify_generic_callable(type: CallableType, target: CallableType,
1115
1115
return_constraint_direction = mypy .constraints .SUBTYPE_OF
1116
1116
1117
1117
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
1122
1141
if not ignore_return :
1123
1142
c = mypy .constraints .infer_constraints (
1124
1143
type .ret_type , target .ret_type , return_constraint_direction )
0 commit comments