Skip to content

Commit f0a5dd3

Browse files
committed
Sync tests again, account for optional kwonly args
1 parent e007c3b commit f0a5dd3

File tree

6 files changed

+17
-12
lines changed

6 files changed

+17
-12
lines changed

mypy/checkexpr.py

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2393,7 +2393,11 @@ def check_argument_count(
23932393
seen_kw = False
23942394
for i, kind in enumerate(callee.arg_kinds):
23952395
mapped_args = formal_to_actual[i]
2396-
seen_kw = seen_kw or any(actual_kinds[k].is_named(star=True) for k in mapped_args)
2396+
seen_kw = (
2397+
seen_kw
2398+
or kind == ArgKind.ARG_NAMED_OPT
2399+
or any(actual_kinds[k].is_named(star=True) for k in mapped_args)
2400+
)
23972401
if kind.is_required() and not mapped_args and not is_unexpected_arg_error:
23982402
# No actual for a mandatory formal
23992403
if (

test-data/unit/check-classes.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2008,7 +2008,7 @@ class D:
20082008
def __set__(self, inst, v, other): pass
20092009
class A:
20102010
f = D()
2011-
A().f = 'x' # E: Too few arguments for "__set__"
2011+
A().f = 'x' # E: Missing positional argument "other" in call to "__set__"
20122012

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

20412041
[case testDescriptorDunderGetWrongArgTypeForInstance]
20422042
from typing import Any

test-data/unit/check-dataclasses.test

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -425,10 +425,11 @@ class Application:
425425
name: str = 'Unnamed'
426426
rating: int = field(kw_only=False) # E: Attributes without a default cannot follow attributes with one
427427

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

434435
[builtins fixtures/dataclasses.pyi]

test-data/unit/check-functools.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -495,9 +495,9 @@ def main5(**d2: Unpack[D2]) -> None:
495495
partial(fn2, **d2)() # E: Extra argument "a2" from **args for "fn2"
496496

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

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

test-data/unit/check-statements.test

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -453,9 +453,9 @@ if object():
453453
if object():
454454
raise MyErrorWithDefault
455455
if object():
456-
raise MyBaseError # E: Too few arguments for "MyBaseError"
456+
raise MyBaseError # E: Missing positional argument "required" in call to "MyBaseError"
457457
if object():
458-
raise MyError # E: Too few arguments for "MyError"
458+
raise MyError # E: Missing positional arguments "required1", "required2" in call to "MyError"
459459
if object():
460460
raise MyKwError # E: Missing named argument "kwonly" for "MyKwError"
461461
[builtins fixtures/exception.pyi]

test-data/unit/check-varargs.test

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -266,7 +266,7 @@ f(*(a, b, b)) # E: Argument 1 to "f" has incompatible type "*tuple[A, B, B]"; ex
266266
f(*(b, b, c)) # E: Argument 1 to "f" has incompatible type "*tuple[B, B, C]"; expected "A"
267267
f(a, *(b, b)) # E: Argument 2 to "f" has incompatible type "*tuple[B, B]"; expected "C"
268268
f(b, *(b, c)) # E: Argument 1 to "f" has incompatible type "B"; expected "A"
269-
f(*(a, b)) # E: Missing positional arguments "b", "c" in call to "f"
269+
f(*(a, b)) # E: Missing positional argument "c" in call to "f"
270270
f(*(a, b, c, c)) # E: Too many arguments for "f"
271271
f(a, *(b, c, c)) # E: Too many arguments for "f"
272272
f(*(a, b, c))
@@ -342,7 +342,7 @@ f(b, *(b, b)) # E: Argument 1 to "f" has incompatible type "B"; expected "A"
342342
f(b, b, *(b,)) # E: Argument 1 to "f" has incompatible type "B"; expected "A"
343343
f(a, a, *(b,)) # E: Argument 2 to "f" has incompatible type "A"; expected "B"
344344
f(a, b, *(a,)) # E: Argument 3 to "f" has incompatible type "*tuple[A]"; expected "B"
345-
f(*()) # E: Too few arguments for "f"
345+
f(*()) # E: Missing positional argument "a" in call to "f"
346346
f(*(a, b, b))
347347
f(a, *(b, b))
348348
f(a, b, *(b,))
@@ -400,7 +400,7 @@ class A: pass
400400
class B: pass
401401

402402
a, b = None, None # type: (A, B)
403-
f(*()) # E: Too few arguments for "f"
403+
f(*()) # E: Missing positional argument "a" in call to "f"
404404
f(a, *[a]) # E: Argument 2 to "f" has incompatible type "*list[A]"; expected "Optional[B]" \
405405
# E: Argument 2 to "f" has incompatible type "*list[A]"; expected "B"
406406
f(a, b, *[a]) # E: Argument 3 to "f" has incompatible type "*list[A]"; expected "B"

0 commit comments

Comments
 (0)