Skip to content

Commit 6c4af8e

Browse files
sobolevnhauntsaninja
authored andcommitted
Fix function call message change for small number of args (#21432)
Refs #21427 I used `2` as a magic number, because in my opinion it is easier to tell the difference when all errors show up for the small number of args. --------- Co-authored-by: hauntsaninja <hauntsaninja@gmail.com>
1 parent 4b8fdca commit 6c4af8e

2 files changed

Lines changed: 46 additions & 2 deletions

File tree

mypy/checkexpr.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1787,6 +1787,7 @@ def check_callable_call(
17871787

17881788
might_have_shifted_args = (
17891789
not self.msg.prefer_simple_messages()
1790+
and len(args) >= 2 # see gh-21427
17901791
and all(k == ARG_POS for k in callee.arg_kinds)
17911792
and all(k == ARG_POS for k in arg_kinds)
17921793
and len(arg_kinds) == len(callee.arg_kinds) - 1

test-data/unit/check-functions.test

Lines changed: 45 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3814,9 +3814,9 @@ f(1, b'x', 1)
38143814
main:3: error: Missing positional argument "y" in call to "f"
38153815

38163816
[case testMissingPositionalArgShiftDetectedFirst]
3817-
def f(x: int, y: str, z: bytes) -> None: ...
3817+
def f(x: int, y: str, z: bytes, last: float) -> None: ...
38183818

3819-
f("hello", b'x')
3819+
f("hello", b'x', 1.5)
38203820
[builtins fixtures/primitives.pyi]
38213821
[out]
38223822
main:3: error: Missing positional argument "x" in call to "f"
@@ -3891,3 +3891,46 @@ f("hello", b'x')
38913891
main:3: error: Missing positional argument "z" in call to "f"
38923892
main:3: error: Argument 1 to "f" has incompatible type "str"; expected "int"
38933893
main:3: error: Argument 2 to "f" has incompatible type "bytes"; expected "str"
3894+
3895+
[case testMissingPositionalArgNamesHigherN]
3896+
# See https://github.com/python/mypy/issues/21427
3897+
def convert2(first: int, second: str) -> None: ...
3898+
3899+
# Possibly omitted arg, but we still issue two errors because there is only one argument
3900+
convert2("hello") # E: Missing positional argument "second" in call to "convert2" \
3901+
# E: Argument 1 to "convert2" has incompatible type "str"; expected "int"
3902+
3903+
# Other cases
3904+
convert2() # E: Missing positional arguments "first", "second" in call to "convert2"
3905+
3906+
convert2("hello", 1) # E: Argument 1 to "convert2" has incompatible type "str"; expected "int" \
3907+
# E: Argument 2 to "convert2" has incompatible type "int"; expected "str"
3908+
3909+
def convert3(first: int, second: str, third: float) -> None: ...
3910+
3911+
# Possibly omitted arg, but we now only issue one error
3912+
convert3("hello", 3.15) # E: Missing positional argument "first" in call to "convert3"
3913+
3914+
# Other cases
3915+
convert3("hello") # E: Missing positional arguments "second", "third" in call to "convert3" \
3916+
# E: Argument 1 to "convert3" has incompatible type "str"; expected "int"
3917+
3918+
convert3(3.15, "hello") # E: Missing positional argument "third" in call to "convert3" \
3919+
# E: Argument 1 to "convert3" has incompatible type "float"; expected "int"
3920+
3921+
def convert4(first: int, second: str, third: float, fourth: bytes) -> None: ...
3922+
3923+
# Possibly omitted arg, but we now only issue one error
3924+
convert4("hello", 3.15, b'') # E: Missing positional argument "first" in call to "convert4"
3925+
3926+
# Other cases
3927+
convert4("hello") # E: Missing positional arguments "second", "third", "fourth" in call to "convert4" \
3928+
# E: Argument 1 to "convert4" has incompatible type "str"; expected "int"
3929+
3930+
convert4("hello", 3.15) # E: Missing positional arguments "third", "fourth" in call to "convert4" \
3931+
# E: Argument 1 to "convert4" has incompatible type "str"; expected "int" \
3932+
# E: Argument 2 to "convert4" has incompatible type "float"; expected "str"
3933+
3934+
convert4(b'', "hello", 3.15) # E: Missing positional argument "fourth" in call to "convert4" \
3935+
# E: Argument 1 to "convert4" has incompatible type "bytes"; expected "int"
3936+
[builtins fixtures/primitives.pyi]

0 commit comments

Comments
 (0)