@@ -1198,10 +1198,29 @@ def unify_generic_callable(type: CallableType, target: CallableType,
1198
1198
return_constraint_direction = mypy .constraints .SUBTYPE_OF
1199
1199
1200
1200
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
1205
1224
if not ignore_return :
1206
1225
c = mypy .constraints .infer_constraints (
1207
1226
type .ret_type , target .ret_type , return_constraint_direction )
0 commit comments