Skip to content
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

Fix 7527: Correct missing positional arguments when more than one optional argument #7547

Merged
merged 1 commit into from
Sep 21, 2019
Merged
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
2 changes: 1 addition & 1 deletion mypy/messages.py
Original file line number Diff line number Diff line change
Expand Up @@ -523,7 +523,7 @@ def too_few_arguments(self, callee: CallableType, context: Context,
if (argument_names is not None and not all(k is None for k in argument_names)
and len(argument_names) >= 1):
num_positional_args = sum(k is None for k in argument_names)
arguments_left = callee.arg_names[num_positional_args:]
arguments_left = callee.arg_names[num_positional_args:callee.min_args]
diff = [k for k in arguments_left if k not in argument_names]
if len(diff) == 1:
msg = 'Missing positional argument'
Expand Down
4 changes: 4 additions & 0 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -2333,6 +2333,10 @@ foo(y=2) # E: Missing positional arguments
def f(a, b, c, d=None) -> None: pass
f(1, 2, d=3) # E: Missing positional argument "c" in call to "f"

[case testMissingArgumentErrorMoreThanOneOptional]
def f(a: int, b=None, c=None) -> None: pass
f(b=4) # E: Missing positional argument "a" in call to "f"

[case testMissingArgumentsError]
def f(a, b, c, d=None) -> None: pass
f(1, d=3) # E: Missing positional arguments "b", "c" in call to "f"
Expand Down