-
-
Notifications
You must be signed in to change notification settings - Fork 2.9k
Wrong "Too many arguments" errors with tuple unpacking #9710
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
This is still an issue for me. Can this get some attention so it can be fixed? |
The sample above uses For example, in the above sample, def foo1(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 def my_function(a: int, b: int, c: int = 0):
return a + b + c
def do_thing(index: 'tuple[int, int] | tuple[int]'):
if len(index) == 1:
return my_function(*index, 2, 3)
elif len(index) == 2:
return my_function(*index, 2)
do_thing((1, )) |
Yes, this would work if mypy were to add type narrowing support for the |
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: