Skip to content
Open
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
1 change: 1 addition & 0 deletions mypy/checkexpr.py
Original file line number Diff line number Diff line change
Expand Up @@ -1787,6 +1787,7 @@ def check_callable_call(

might_have_shifted_args = (
not self.msg.prefer_simple_messages()
and len(args) >= 2 # see gh-21427
and all(k == ARG_POS for k in callee.arg_kinds)
and all(k == ARG_POS for k in arg_kinds)
and len(arg_kinds) == len(callee.arg_kinds) - 1
Expand Down
45 changes: 43 additions & 2 deletions test-data/unit/check-functions.test
Original file line number Diff line number Diff line change
Expand Up @@ -3814,9 +3814,9 @@ f(1, b'x', 1)
main:3: error: Missing positional argument "y" in call to "f"

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

f("hello", b'x')
f("hello", b'x', 1.5)
[builtins fixtures/primitives.pyi]
[out]
main:3: error: Missing positional argument "x" in call to "f"
Expand Down Expand Up @@ -3891,3 +3891,44 @@ f("hello", b'x')
main:3: error: Missing positional argument "z" in call to "f"
main:3: error: Argument 1 to "f" has incompatible type "str"; expected "int"
main:3: error: Argument 2 to "f" has incompatible type "bytes"; expected "str"

[case testMissingPositionalArgNames2]
# See gh-21427:
def convert2(first: int, second: str) -> None: ...

convert2() # E: Missing positional arguments "first", "second" in call to "convert2"

convert2("hello") # E: Missing positional argument "second" in call to "convert2" \
# E: Argument 1 to "convert2" has incompatible type "str"; expected "int"

convert2("hello", 1) # E: Argument 1 to "convert2" has incompatible type "str"; expected "int" \
# E: Argument 2 to "convert2" has incompatible type "int"; expected "str"
[builtins fixtures/primitives.pyi]

[case testMissingPositionalArgNames3]
def convert3(first: int, second: str, third: float) -> None: ...

convert3("hello") # E: Missing positional arguments "second", "third" in call to "convert3" \
# E: Argument 1 to "convert3" has incompatible type "str"; expected "int"

convert3(3.15, "hello") # E: Missing positional argument "third" in call to "convert3" \
# E: Argument 1 to "convert3" has incompatible type "float"; expected "int"

convert3("hello", 3.15) # E: Missing positional argument "first" in call to "convert3"
[builtins fixtures/primitives.pyi]

[case testMissingPositionalArgNames4]
def convert4(first: int, second: str, third: float, fourth: bytes) -> None: ...

convert4("hello") # E: Missing positional arguments "second", "third", "fourth" in call to "convert4" \
# E: Argument 1 to "convert4" has incompatible type "str"; expected "int"

convert4("hello", 3.15) # E: Missing positional arguments "third", "fourth" in call to "convert4" \
# E: Argument 1 to "convert4" has incompatible type "str"; expected "int" \
# E: Argument 2 to "convert4" has incompatible type "float"; expected "str"

convert4(b'', "hello", 3.15) # E: Missing positional argument "fourth" in call to "convert4" \
# E: Argument 1 to "convert4" has incompatible type "bytes"; expected "int"

convert4("hello", 3.15, b'') # E: Missing positional argument "first" in call to "convert4"
[builtins fixtures/primitives.pyi]
Loading