Skip to content

Commit bd0864e

Browse files
PattenRmsullivan
authored andcommitted
Correct missing positional args when optional args present (python#7547)
Fixes python#7527
1 parent 959eb76 commit bd0864e

File tree

2 files changed

+5
-1
lines changed

2 files changed

+5
-1
lines changed

mypy/messages.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -523,7 +523,7 @@ def too_few_arguments(self, callee: CallableType, context: Context,
523523
if (argument_names is not None and not all(k is None for k in argument_names)
524524
and len(argument_names) >= 1):
525525
num_positional_args = sum(k is None for k in argument_names)
526-
arguments_left = callee.arg_names[num_positional_args:]
526+
arguments_left = callee.arg_names[num_positional_args:callee.min_args]
527527
diff = [k for k in arguments_left if k not in argument_names]
528528
if len(diff) == 1:
529529
msg = 'Missing positional argument'

test-data/unit/check-functions.test

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2333,6 +2333,10 @@ foo(y=2) # E: Missing positional arguments
23332333
def f(a, b, c, d=None) -> None: pass
23342334
f(1, 2, d=3) # E: Missing positional argument "c" in call to "f"
23352335

2336+
[case testMissingArgumentErrorMoreThanOneOptional]
2337+
def f(a: int, b=None, c=None) -> None: pass
2338+
f(b=4) # E: Missing positional argument "a" in call to "f"
2339+
23362340
[case testMissingArgumentsError]
23372341
def f(a, b, c, d=None) -> None: pass
23382342
f(1, d=3) # E: Missing positional arguments "b", "c" in call to "f"

0 commit comments

Comments
 (0)
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