pyright
pyright copied to clipboard
wrong type inferred when (Tuple[*Ts]) -> Tuple[Union[*Ts], ...] is applied to tuple of tuple
Describe the bug
function (Tuple[*Ts]) -> Tuple[Union[*Ts], ...] unexpectedly flatten nested Tuple.
To Reproduce
#!/usr/bin/env python3
from typing import Tuple, Union
from typing_extensions import TypeVarTuple, reveal_type
Ts = TypeVarTuple("Ts")
def f(t: "Tuple[*Ts]") -> "Tuple[Union[*Ts], ...]": ...
reveal_type(f)
good = f((1, "foo"))
reveal_type(good)
r = f(((1, "foo"),))
reveal_type(r)
information: Type of "f" is "(t: Tuple[*Ts@f]) -> Tuple[Union[*Ts@f], ...]"
information: Type of "good" is "Tuple[int | str, ...]"
information: Type of "r" is "Tuple[Literal[1], Literal['foo']]"
Expected behavior
type Tuple[Tuple[int, str], ...] is infered for r
VS Code extension or command-line
command-line tool, 1.1.280
This will be addressed in the next release.
This is addressed in pyright 1.1.281, which I just published. It will also be included in a future release of pylance.