Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -970,8 +970,9 @@ def too_many_positional_arguments(self, callee: CallableType, context: Context)
msg = "Too many positional arguments"
else:
msg = "Too many positional arguments" + for_function(callee)
self.fail(msg, context)
self.fail(msg, context, code=codes.CALL_ARG)
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():
Expand Down
15 changes: 15 additions & 0 deletions test-data/unit/check-kwargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-namedtuple.test
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 1 addition & 0 deletions test-data/unit/check-type-aliases.test
Original file line number Diff line number Diff line change
Expand Up @@ -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]
Expand Down
Loading