You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
$ 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
The text was updated successfully, but these errors were encountered:
torfsen
changed the title
Wrong/misleading "Too many arguments" errors with tuple unpacking
Wrong "Too many arguments" errors with tuple unpacking
Nov 10, 2020
The sample above uses tuple with no type arguments. That's a problem because mypy can't determine the intended length of the tuple. If you provide type arguments that specify a tuple length, you can avoid type errors.
For example, in the above sample, foo1 could be changed as follows:
deffoo1(t: tuple[Any, int]) ->None:
x(*t[:1], 1)
Mypy is arguably doing the correct thing here. If you don't like the current behavior, you are welcome to propose a different behavior and submit a PR to implement that behavior.
This example is pretty clear about the length of its tuples and it still gets errors on both return statements of the second function. It seemed that the if len(index) == n expression wasn't filtering what the tuple could be.
Bug Report
I'm getting wrong or misleading "Too many arguments" errors when using tuple unpacking in function calls.
To Reproduce
mypy reports:
(Line 7 is the call to
x
infoo1
)Expected Behavior
The call to
x
infoo1
will never have too many arguments -- it has either 1 (ift
is empty) or 2 (ift
is not empty). I would have expected an error regarding the possibility oft
being empty (i.e. "Potentially not enough arguments").Also I think that
foo1
andfoo2
share the same issues regarding their calls ofx
, so I would have expected to get the same errors for both of them.Actual Behavior
The call to
x
infoo1
is reported, but the call tox
infoo2
isn't. Interestingly, fixing the tuple length (as infoo3
) seems to fix the issue.Your Environment
mypy.ini
(and other config files): NoneThe text was updated successfully, but these errors were encountered: