pyre-check icon indicating copy to clipboard operation
pyre-check copied to clipboard

Callable with variadic args does not accept function with `*args: int`

Open mrahtz opened this issue 3 years ago • 1 comments

The following example...

from typing import Callable
from pyre_extensions import TypeVarTuple, Unpack

Ts = TypeVarTuple('Ts')

def foo(func: Callable[[Unpack[Ts]], None]):
    pass

def bar(*args: int):
    pass

foo(bar)

...should type-check correctly; foo expects a function with a single variadic argument, and that's exactly what bar is. But Pyre (0.9.10) says:

test.py:12:4 Incompatible parameter type [6]:
In call `foo`, for 1st positional only parameter expected
`typing.Callable[[Variable(*test.Ts)], None]` but got
`typing.Callable(bar)[[Variable(int)], typing.Any]`.

It works if *args isn't annotated:

def bar(*args):
    pass

It also works if *args is annotated as explicitly variadic:


def bar(*args: Unpack[tuple[int, ...]]):
    pass

So I'm guessing this is some kind of bug with the logic for determining whether *args is variadic or not...?

(@pradeep90, I'm guessing this is best addressed by you.)

pyre_rage.log

mrahtz avatar Feb 07 '22 19:02 mrahtz

@mrahtz Yes, this is a bug. We don't treat them as identical. Will fix.

pradeep90 avatar Feb 07 '22 20:02 pradeep90