pyright icon indicating copy to clipboard operation
pyright copied to clipboard

forwarding Callable and Tuple with Unpack causes error

Open pinterior opened this issue 4 years ago • 2 comments

Describe the bug

forwarding Callable and Tuple parameters to another function with same type annotation causes error.

To Reproduce

from typing import Callable, Tuple
from typing_extensions import TypeVarTuple, Unpack

Ts = TypeVarTuple("Ts")

def ct0(x: Callable[[Unpack[Ts]], None], y: Tuple[Unpack[Ts]]):
    pass

def ct1(x: Callable[[Unpack[Ts]], None], y: Tuple[Unpack[Ts]]):
    ct0(x, y)
 Argument of type "Tuple[*Ts@ct1]" cannot be assigned to parameter "y" of type "Tuple[*Ts@ct0]" in function "ct0"
    "Tuple[*Ts@ct1]" is incompatible with "Tuple[*Ts@ct0]"
      Tuple entry 1 is incorrect type
        Type "*tuple[*Ts@ct1]" cannot be assigned to type "*Ts@ct1"
          "*tuple[*Ts@ct1]" is incompatible with "tuple[()]"
            Element size mismatch; expected 0 but received 1 (reportGeneralTypeIssues)

Expected behavior

code above should be accepted with no error

VS Code extension or command-line

command-line, 1.1.277

Additional context

if both parameter are Callable or are Tuple, there's no problem.

from typing import Callable, Tuple
from typing_extensions import TypeVarTuple, Unpack

Ts = TypeVarTuple("Ts")

def cc0(x: Callable[[Unpack[Ts]], None], y: Callable[[Unpack[Ts]], None]):
    pass

def cc1(x: Callable[[Unpack[Ts]], None], y: Callable[[Unpack[Ts]], None]):
    cc0(x, y)  # ok

def tt0(x: Tuple[Unpack[Ts]], y: Tuple[Unpack[Ts]]):
    pass

def tt1(x: Tuple[Unpack[Ts]], y: Tuple[Unpack[Ts]]):
    tt0(x, y)  # ok

pinterior avatar Oct 31 '22 04:10 pinterior

This bug will be fixed in the next release.

erictraut avatar Oct 31 '22 15:10 erictraut

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

erictraut avatar Nov 02 '22 04:11 erictraut