4444 ArgKind ,
4545 CallExpr ,
4646 Context ,
47+ Decorator ,
4748 Expression ,
4849 FuncDef ,
4950 IndexExpr ,
@@ -1104,7 +1105,7 @@ def no_variant_matches_arguments(
11041105 all_valid_kwargs : set [str ] = set ()
11051106 for item in overload .items :
11061107 for i , arg_name in enumerate (item .arg_names ):
1107- if arg_name is not None and arg_kinds [i ] != ARG_STAR :
1108+ if arg_name is not None and item . arg_kinds [i ] != ARG_STAR :
11081109 all_valid_kwargs .add (arg_name )
11091110 if item .is_kw_arg :
11101111 all_valid_kwargs .clear ()
@@ -1120,28 +1121,41 @@ def no_variant_matches_arguments(
11201121 for kwarg_name , kwarg_type in unexpected_kwargs :
11211122 matching_type_args : list [str ] = []
11221123 not_matching_type_args : list [str ] = []
1124+ matching_variant : CallableType | None = None
11231125
11241126 for item in overload .items :
1127+ has_type_match = False
11251128 for i , formal_type in enumerate (item .arg_types ):
11261129 formal_name = item .arg_names [i ]
11271130 if formal_name is not None and item .arg_kinds [i ] != ARG_STAR :
11281131 if is_subtype (kwarg_type , formal_type ):
11291132 if formal_name not in matching_type_args :
11301133 matching_type_args .append (formal_name )
1134+ has_type_match = True
11311135 else :
11321136 if formal_name not in not_matching_type_args :
11331137 not_matching_type_args .append (formal_name )
1138+ if has_type_match and matching_variant is None :
1139+ matching_variant = item
11341140
11351141 matches = best_matches (kwarg_name , matching_type_args , n = 3 )
11361142 if not matches :
11371143 matches = best_matches (kwarg_name , not_matching_type_args , n = 3 )
11381144
11391145 msg = f'Unexpected keyword argument "{ kwarg_name } "' + for_func
1146+
1147+ if matching_variant is not None and matching_variant .definition is not None :
1148+ defn = matching_variant .definition
1149+ if isinstance (defn , Decorator ):
1150+ func_line = defn .func .line
1151+ else :
1152+ func_line = defn .line
1153+ msg += f" defined on line { func_line } "
1154+
11401155 if matches :
11411156 msg += f"; did you mean { pretty_seq (matches , 'or' )} ?"
11421157 self .fail (msg , context , code = code )
11431158
1144- # do we want to still show possible overload variants as a note?
11451159 return
11461160
11471161 arg_types_str = ", " .join (format_type (arg , self .options ) for arg in arg_types )
0 commit comments