From 85996a775f33391fc716e391bfa2c7e7d06dc2e9 Mon Sep 17 00:00:00 2001 From: KevinRK29 Date: Fri, 13 Feb 2026 02:45:52 -0500 Subject: [PATCH 1/4] extracted to make a helper function and added more usages --- mypy/messages.py | 8 ++++++++ 1 file changed, 8 insertions(+) diff --git a/mypy/messages.py b/mypy/messages.py index 59b1b3db07cc..85b428b30633 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -937,10 +937,12 @@ def too_few_arguments( else: msg = "Too few arguments" + for_function(callee) self.fail(msg, context, code=codes.CALL_ARG) + self.note_defined_here(callee, context) def missing_named_argument(self, callee: CallableType, context: Context, name: str) -> None: msg = f'Missing named argument "{name}"' + for_function(callee) self.fail(msg, context, code=codes.CALL_ARG) + self.note_defined_here(callee, context) def too_many_arguments(self, callee: CallableType, context: Context) -> None: if self.prefer_simple_messages(): @@ -948,6 +950,7 @@ def too_many_arguments(self, callee: CallableType, context: Context) -> None: else: msg = "Too many arguments" + for_function(callee) self.fail(msg, context, code=codes.CALL_ARG) + self.note_defined_here(callee, context) self.maybe_note_about_special_args(callee, context) def too_many_arguments_from_typed_dict( @@ -969,6 +972,7 @@ def too_many_positional_arguments(self, callee: CallableType, context: Context) else: msg = "Too many positional arguments" + for_function(callee) self.fail(msg, context) + self.note_defined_here(callee, context) self.maybe_note_about_special_args(callee, context) def maybe_note_about_special_args(self, callee: CallableType, context: Context) -> None: @@ -1011,6 +1015,10 @@ def unexpected_keyword_argument( self.unexpected_keyword_argument_for_function( for_function(callee), name, context, matches=matches ) + self.note_defined_here(callee, context) + + def note_defined_here(self, callee: CallableType, context: Context) -> None: + """Add a note pointing to the definition of the callee.""" module = find_defining_module(self.modules, callee) if ( module From 69b553340f35bed73529b577e41bff64acd2aeb1 Mon Sep 17 00:00:00 2001 From: KevinRK29 Date: Fri, 20 Feb 2026 04:49:03 -0500 Subject: [PATCH 2/4] scope note to just missing_named_argument error --- mypy/messages.py | 3 --- 1 file changed, 3 deletions(-) diff --git a/mypy/messages.py b/mypy/messages.py index 85b428b30633..65cd19a27627 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -937,7 +937,6 @@ def too_few_arguments( else: msg = "Too few arguments" + for_function(callee) self.fail(msg, context, code=codes.CALL_ARG) - self.note_defined_here(callee, context) def missing_named_argument(self, callee: CallableType, context: Context, name: str) -> None: msg = f'Missing named argument "{name}"' + for_function(callee) @@ -950,7 +949,6 @@ def too_many_arguments(self, callee: CallableType, context: Context) -> None: else: msg = "Too many arguments" + for_function(callee) self.fail(msg, context, code=codes.CALL_ARG) - self.note_defined_here(callee, context) self.maybe_note_about_special_args(callee, context) def too_many_arguments_from_typed_dict( @@ -972,7 +970,6 @@ def too_many_positional_arguments(self, callee: CallableType, context: Context) else: msg = "Too many positional arguments" + for_function(callee) self.fail(msg, context) - self.note_defined_here(callee, context) self.maybe_note_about_special_args(callee, context) def maybe_note_about_special_args(self, callee: CallableType, context: Context) -> None: From b8e1d0642b57fb9b68211b6de584ffed79a58441 Mon Sep 17 00:00:00 2001 From: KevinRK29 Date: Fri, 20 Feb 2026 04:51:48 -0500 Subject: [PATCH 3/4] update --- mypy/messages.py | 1 - 1 file changed, 1 deletion(-) diff --git a/mypy/messages.py b/mypy/messages.py index 65cd19a27627..9540828012b0 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -1015,7 +1015,6 @@ def unexpected_keyword_argument( self.note_defined_here(callee, context) def note_defined_here(self, callee: CallableType, context: Context) -> None: - """Add a note pointing to the definition of the callee.""" module = find_defining_module(self.modules, callee) if ( module From b22f220a0ecf15034c42b250996b8c0309804d55 Mon Sep 17 00:00:00 2001 From: KevinRK29 Date: Fri, 20 Feb 2026 11:09:59 -0500 Subject: [PATCH 4/4] added test --- test-data/unit/check-kwargs.test | 18 ++++++++++++++++++ 1 file changed, 18 insertions(+) diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index a0dc2c2686b7..c8653143bd9d 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -480,6 +480,24 @@ tmp/m.py:1: error: Unsupported operand types for + ("int" and "str") main:2: error: Unexpected keyword argument "x" for "A" main:2: note: "A" defined in "m" +[case testMissingNamedArgumentFromOtherModule] +import m +m.f(1) +m.f(a=1) +[file m.py] +def f(a: int, *, b: str) -> None: + pass +[out] +main:2: error: Missing named argument "b" for "f" +main:2: note: "f" defined in "m" +main:3: error: Missing named argument "b" for "f" +main:3: note: "f" defined in "m" + +[case testMissingNamedArgumentForSameModule] +def f(a: int, *, b: str) -> None: + pass +f(1) # E: Missing named argument "b" for "f" + [case testStarArgsAndKwArgsSpecialCase] from typing import Dict, Mapping