Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 7560ee0

Browse files
rafaelcaricioilevkivskyi
authored andcommitted
Show only the missing argument names in error msg (#6795)
Fixes #3963
1 parent 34993eb commit 7560ee0

File tree

2 files changed

+11
-1
lines changed

2 files changed

+11
-1
lines changed

mypy/messages.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -644,7 +644,9 @@ def too_few_arguments(self, callee: CallableType, context: Context,
644644
argument_names: Optional[Sequence[Optional[str]]]) -> None:
645645
if (argument_names is not None and not all(k is None for k in argument_names)
646646
and len(argument_names) >= 1):
647-
diff = [k for k in callee.arg_names if k not in argument_names]
647+
num_positional_args = sum(k is None for k in argument_names)
648+
arguments_left = callee.arg_names[num_positional_args:]
649+
diff = [k for k in arguments_left if k not in argument_names]
648650
if len(diff) == 1:
649651
msg = 'Missing positional argument'
650652
else:

test-data/unit/check-functions.test

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2328,6 +2328,14 @@ def foo(__b: int, x: int, y: int) -> int: pass
23282328
foo(x=2, y=2) # E: Missing positional argument
23292329
foo(y=2) # E: Missing positional arguments
23302330

2331+
[case testMissingArgumentError]
2332+
def f(a, b, c, d=None) -> None: pass
2333+
f(1, 2, d=3) # E: Missing positional argument "c" in call to "f"
2334+
2335+
[case testMissingArgumentsError]
2336+
def f(a, b, c, d=None) -> None: pass
2337+
f(1, d=3) # E: Missing positional arguments "b", "c" in call to "f"
2338+
23312339
[case testReturnTypeLineNumberWithDecorator]
23322340
def dec(f): pass
23332341

0 commit comments

Comments
 (0)