pyright
pyright copied to clipboard
Tuple[*Ps] is not assignable to parameter of Iterable[Union[*Ps]]
Describe the bug
Tuple[*Ps] is assignable to local variable of Iterable[Union[*Ps]], but is not assignable to parameter of Iterable[Union[*Ps]].
To Reproduce
#!/usr/bin/env python3
from typing import Iterable, Tuple, Union
from typing_extensions import TypeVarTuple
Ps = TypeVarTuple("Ps")
t = (1, "foo")
_: Iterable[Union[int, str]] = t # ok
def g(t: "Tuple[*Ps]") -> "Tuple[*Ps]":
_: "Iterable[Union[*Ps]]" = t # ok
return t
def f(t: "Tuple[*Ps]", i: "Iterable[Union[*Ps]]"):
pass
f(t, t) # error
error: Argument of type "tuple[Literal[1], Literal['foo']]" cannot be assigned to parameter "i" of type "Iterable[*Ps@f]" in function "f"
"tuple[Literal[1], Literal['foo']]" is incompatible with "Iterable[*Ps@f]"
TypeVar "_T_co@Iterable" is covariant
Type "*tuple[int, str]" cannot be assigned to type "*tuple[Literal[1, 'foo']]" (reportGeneralTypeIssues)
Expected behavior
no error reported
VS Code extension or command-line
command-line tool, 1.1.279
Additional context
Iterable takes only one type parameter. so Iterable[*Ps@f] in error message is a bit confusing
Yes, this is correct. tuple[*Ps] is not type compatible with Iterable[Union[*Ps]].
sure, thanks.