From 7be6350ecc43255b486f99648065453080f5f286 Mon Sep 17 00:00:00 2001 From: Kevin Kannammalil Date: Tue, 5 May 2026 00:08:25 -0400 Subject: [PATCH] added note to too_many_positional_arguments --- mypy/messages.py | 1 + test-data/unit/check-kwargs.test | 15 +++++++++++++++ test-data/unit/check-namedtuple.test | 1 + test-data/unit/check-type-aliases.test | 1 + 4 files changed, 18 insertions(+) diff --git a/mypy/messages.py b/mypy/messages.py index 3de66c7c6082c..b4a92a02fde03 100644 --- a/mypy/messages.py +++ b/mypy/messages.py @@ -972,6 +972,7 @@ def too_many_positional_arguments(self, callee: CallableType, context: Context) msg = "Too many positional arguments" + for_function(callee) self.fail(msg, context) self.maybe_note_about_special_args(callee, context) + self.note_defined_here(callee, context) def maybe_note_about_special_args(self, callee: CallableType, context: Context) -> None: if self.prefer_simple_messages(): diff --git a/test-data/unit/check-kwargs.test b/test-data/unit/check-kwargs.test index f11c2b6f4fc40..6f5e11d85ee48 100644 --- a/test-data/unit/check-kwargs.test +++ b/test-data/unit/check-kwargs.test @@ -495,6 +495,21 @@ def f(a: int, *, b: str) -> None: pass f(1) # E: Missing named argument "b" for "f" +[case testTooManyPositionalArgumentsFromOtherModule] +import m +m.f(1, 2) +[file m.py] +def f(a: int, *, b: int) -> None: + pass +[out] +main:2: error: Too many positional arguments for "f" +main:2: note: "f" defined in "m" + +[case testTooManyPositionalArgumentsForSameModule] +def f(a: int, *, b: int) -> None: + pass +f(1, 2) # E: Too many positional arguments for "f" + [case testStarArgsAndKwArgsSpecialCase] from typing import Dict, Mapping diff --git a/test-data/unit/check-namedtuple.test b/test-data/unit/check-namedtuple.test index 285ae92325d8e..158b95aa598d0 100644 --- a/test-data/unit/check-namedtuple.test +++ b/test-data/unit/check-namedtuple.test @@ -132,6 +132,7 @@ main:5: error: Argument "rename" to "namedtuple" has incompatible type "str"; ex main:6: error: Unexpected keyword argument "unrecognized_arg" for "namedtuple" main:6: note: "namedtuple" defined in "collections" main:7: error: Too many positional arguments for "namedtuple" +main:7: note: "namedtuple" defined in "collections" [case testNamedTupleDefaults] from collections import namedtuple diff --git a/test-data/unit/check-type-aliases.test b/test-data/unit/check-type-aliases.test index 4d68f93a21eda..e48700c69e38e 100644 --- a/test-data/unit/check-type-aliases.test +++ b/test-data/unit/check-type-aliases.test @@ -1112,6 +1112,7 @@ reveal_type(t3) # N: Revealed type is "Any" T4 = TypeAliasType("T4") # E: Missing positional argument "value" in call to "TypeAliasType" T5 = TypeAliasType("T5", int, str) # E: Too many positional arguments for "TypeAliasType" \ + # N: "TypeAliasType" defined in "typing_extensions" \ # E: Argument 3 to "TypeAliasType" has incompatible type "type[str]"; expected "tuple[TypeVar? | ParamSpec? | TypeVarTuple?, ...]" [builtins fixtures/tuple.pyi] [typing fixtures/typing-full.pyi]