Open
Description
Bug Report
I'm getting wrong or misleading "Too many arguments" errors when using tuple unpacking in function calls.
To Reproduce
from typing import Tuple
def x(x: int, y: int) -> None:
print(x, y)
def foo1(t: tuple) -> None:
x(*t[:1], 1)
def foo2(t: tuple) -> None:
x(*t[:2])
def foo3(t: Tuple[int]) -> None:
x(*t[:1], 1)
mypy reports:
$ mypy sandbox.py
sandbox.py:7: error: Too many arguments for "x"
Found 1 error in 1 file (checked 1 source file)
(Line 7 is the call to x
in foo1
)
Expected Behavior
The call to x
in foo1
will never have too many arguments -- it has either 1 (if t
is empty) or 2 (if t
is not empty). I would have expected an error regarding the possibility of t
being empty (i.e. "Potentially not enough arguments").
Also I think that foo1
and foo2
share the same issues regarding their calls of x
, so I would have expected to get the same errors for both of them.
Actual Behavior
The call to x
in foo1
is reported, but the call to x
in foo2
isn't. Interestingly, fixing the tuple length (as in foo3
) seems to fix the issue.
Your Environment
- Mypy version used: 0.790
- Mypy command-line flags: None
- Mypy configuration options from
mypy.ini
(and other config files): None - Python version used: 3.8.5
- Operating system and version: Ubuntu 18.04.5