zip two Tuple[*Ps]s results wrong sized Tuple
Describe the bug
call zip with two Tuple[int, str] via TypeVarTuples got Tuple[int, str, int, str] instead of Tuple[int|str, int|str].
To Reproduce
#!/usr/bin/env python3
from typing import Any, Tuple
from typing_extensions import TypeVarTuple, Unpack
Ps = TypeVarTuple("Ps")
def f(a: Tuple[Unpack[Ps]], b: Tuple[Unpack[Ps]]):
for i in zip(a, b):
yield i
for i in f((1,"foo"), (2, "bar")):
x: Tuple[Any, Any] = i
print(x)
Expression of type "tuple[int, str, int, str]" cannot be assigned to declared type "Tuple[Any, Any]"
"tuple[int, str, int, str]" is incompatible with "Tuple[Any, Any]"
Element size mismatch; expected 2 but received 4 (reportGeneralTypeIssues)
Expected behavior
no error reported
VS Code extension or command-line
command-line tool, 1.1.279
I think pyright is evaluating the right types in this case. The problem is with the typeshed definition of zip. I think this is related to this bug report.
I don't think there's a way to correctly describe the functionality performed by zip in today's type system, so it's unlikely that the maintainers of typeshed will be able to fix this, but you could file a bug in the typeshed repo if you'd like.
sure, but unexpected number of type parameters is still bit mysterious.
My analysis of this issue was incorrect. This isn't a problem with the zip definition. It's a legitimate bug in pyright, as you demonstrated in issue https://github.com/microsoft/pyright/issues/4190.
I've found and fixed the underlying bug. It will be addressed in the next release.
This is addressed in pyright 1.1.280, which I just published. It will also be included in a future version of pylance.