Skip to content

Fix wrong names listed in "too few arguments" message #19354

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Draft
wants to merge 4 commits into
base: master
Choose a base branch
from
Draft
Show file tree
Hide file tree
Changes from 1 commit
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
Prev Previous commit
Sync tests again, account for optional kwonly args
  • Loading branch information
sterliakov committed Jun 29, 2025
commit f0a5dd3fe8b63b67c84021373bd09342a95214dd
6 changes: 5 additions & 1 deletion mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -2393,7 +2393,11 @@ def check_argument_count(
seen_kw = False
for i, kind in enumerate(callee.arg_kinds):
mapped_args = formal_to_actual[i]
seen_kw = seen_kw or any(actual_kinds[k].is_named(star=True) for k in mapped_args)
seen_kw = (
seen_kw
or kind == ArgKind.ARG_NAMED_OPT
or any(actual_kinds[k].is_named(star=True) for k in mapped_args)
)
if kind.is_required() and not mapped_args and not is_unexpected_arg_error:
# No actual for a mandatory formal
if (
Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-classes.test
Original file line number Diff line number Diff line change
Expand Up @@ -2008,7 +2008,7 @@ class D:
def __set__(self, inst, v, other): pass
class A:
f = D()
A().f = 'x' # E: Too few arguments for "__set__"
A().f = 'x' # E: Missing positional argument "other" in call to "__set__"

[case testDescriptorDunderSetWrongArgTypes]
class D:
Expand Down Expand Up @@ -2036,7 +2036,7 @@ class D:
def __get__(self, inst, own, other): pass
class A:
f = D()
A().f = 'x' # E: Too few arguments for "__get__"
A().f = 'x' # E: Missing positional argument "other" in call to "__get__"

[case testDescriptorDunderGetWrongArgTypeForInstance]
from typing import Any
Expand Down
3 changes: 2 additions & 1 deletion test-data/unit/check-dataclasses.test
Original file line number Diff line number Diff line change
Expand Up @@ -425,10 +425,11 @@ class Application:
name: str = 'Unnamed'
rating: int = field(kw_only=False) # E: Attributes without a default cannot follow attributes with one

reveal_type(Application) # N: Revealed type is "def (name: builtins.str =, rating: builtins.int) -> __main__.Application"
Application(name='name', rating=5)
Application('name', 123)
Application('name', rating=123)
Application() # E: Missing positional argument "name" in call to "Application"
Application() # E: Too few arguments for "Application"
Application('name') # E: Too few arguments for "Application"

[builtins fixtures/dataclasses.pyi]
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-functools.test
Original file line number Diff line number Diff line change
Expand Up @@ -495,9 +495,9 @@ def main5(**d2: Unpack[D2]) -> None:
partial(fn2, **d2)() # E: Extra argument "a2" from **args for "fn2"

def main6(a2good: A2Good, a2bad: A2Bad, **d1: Unpack[D1]) -> None:
partial(fn3, **d1)() # E: Missing positional argument "a1" in call to "fn3"
partial(fn3, **d1)() # E: Missing named argument "a2" for "fn3"
partial(fn3, **d1)("asdf") # E: Too many positional arguments for "fn3" \
# E: Too few arguments for "fn3" \
# E: Missing named argument "a2" for "fn3" \
# E: Argument 1 to "fn3" has incompatible type "str"; expected "int"
partial(fn3, **d1)(a2="asdf")
partial(fn3, **d1)(**a2good)
Expand Down Expand Up @@ -530,7 +530,7 @@ reveal_type(first_kw(args=[1])) # N: Revealed type is "builtins.int"

# TODO: this is indeed invalid, but the error is incomprehensible.
first_kw([1]) # E: Too many positional arguments for "get" \
# E: Too few arguments for "get" \
# E: Missing named argument "args" for "get" \
# E: Argument 1 to "get" has incompatible type "list[int]"; expected "int"
[builtins fixtures/list.pyi]

Expand Down
4 changes: 2 additions & 2 deletions test-data/unit/check-statements.test
Original file line number Diff line number Diff line change
Expand Up @@ -453,9 +453,9 @@ if object():
if object():
raise MyErrorWithDefault
if object():
raise MyBaseError # E: Too few arguments for "MyBaseError"
raise MyBaseError # E: Missing positional argument "required" in call to "MyBaseError"
if object():
raise MyError # E: Too few arguments for "MyError"
raise MyError # E: Missing positional arguments "required1", "required2" in call to "MyError"
if object():
raise MyKwError # E: Missing named argument "kwonly" for "MyKwError"
[builtins fixtures/exception.pyi]
Expand Down
6 changes: 3 additions & 3 deletions test-data/unit/check-varargs.test
Original file line number Diff line number Diff line change
Expand Up @@ -266,7 +266,7 @@ f(*(a, b, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, B, B]"; ex
f(*(b, b, c)) # E: Argument 1 to "f" has incompatible type "*tuple[B, B, C]"; expected "A"
f(a, *(b, b)) # E: Argument 2 to "f" has incompatible type "*tuple[B, B]"; expected "C"
f(b, *(b, c)) # E: Argument 1 to "f" has incompatible type "B"; expected "A"
f(*(a, b)) # E: Missing positional arguments "b", "c" in call to "f"
f(*(a, b)) # E: Missing positional argument "c" in call to "f"
f(*(a, b, c, c)) # E: Too many arguments for "f"
f(a, *(b, c, c)) # E: Too many arguments for "f"
f(*(a, b, c))
Expand Down Expand Up @@ -342,7 +342,7 @@ f(b, *(b, b)) # E: Argument 1 to "f" has incompatible type "B"; expected "A"
f(b, b, *(b,)) # E: Argument 1 to "f" has incompatible type "B"; expected "A"
f(a, a, *(b,)) # E: Argument 2 to "f" has incompatible type "A"; expected "B"
f(a, b, *(a,)) # E: Argument 3 to "f" has incompatible type "*tuple[A]"; expected "B"
f(*()) # E: Too few arguments for "f"
f(*()) # E: Missing positional argument "a" in call to "f"
f(*(a, b, b))
f(a, *(b, b))
f(a, b, *(b,))
Expand Down Expand Up @@ -400,7 +400,7 @@ class A: pass
class B: pass

a, b = None, None # type: (A, B)
f(*()) # E: Too few arguments for "f"
f(*()) # E: Missing positional argument "a" in call to "f"
f(a, *[a]) # E: Argument 2 to "f" has incompatible type "*list[A]"; expected "Optional[B]" \
# E: Argument 2 to "f" has incompatible type "*list[A]"; expected "B"
f(a, b, *[a]) # E: Argument 3 to "f" has incompatible type "*list[A]"; expected "B"
Expand Down
pFad - Phonifier reborn

Pfad - The Proxy pFad of © 2024 Garber Painting. All rights reserved.

Note: This service is not intended for secure transactions such as banking, social media, email, or purchasing. Use at your own risk. We assume no liability whatsoever for broken pages.


Alternative Proxies:

Alternative Proxy

pFad Proxy

pFad v3 Proxy

pFad v4 Proxy