pyright icon indicating copy to clipboard operation
pyright copied to clipboard

wrong type inferred when (Tuple[*Ts]) -> Tuple[Union[*Ts], ...] is applied to tuple of tuple

Open pinterior opened this issue 4 years ago • 2 comments

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

pinterior avatar Nov 16 '22 12:11 pinterior

This will be addressed in the next release.

erictraut avatar Nov 18 '22 17:11 erictraut

This is addressed in pyright 1.1.281, which I just published. It will also be included in a future release of pylance.

erictraut avatar Nov 23 '22 04:11 erictraut