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

Incompatible parameter type: Expected typing.Callable

Open rohori opened this issue 3 years ago • 1 comments

Pyre Bug

Bug description The parameter type is reported incompatible.

Reproduction steps

from typing import Callable, Dict, Tuple, TypeVar

K = TypeVar("K") # key
V = TypeVar("V") # value
R = TypeVar("R") # result
F = TypeVar("F") # first
S = TypeVar("S") # second

def vmap(f: Callable[[V], R], d: Dict[K, V]) -> Dict[K, R]:
    """map over dict values."""
    return {k: f(v) for (k, v) in d.items()}

def first(t: Tuple[F, S]) -> F:
    """First item of 2-tuple."""
    return t[0]

a: Dict[str, Tuple[str, int]] = {"en": ("hello", 5), "ja": ("こんにちは", 5)}

print(vmap(first, a)) # new dict with same keys and first element of values

Expected behavior successful type check, where vmap.V = Tuple[first.F, first.S] = (str, int) vmap.R = first.F = str vmap.K = str

Logs

Incompatible parameter type [6]: Expected `typing.Callable[[Variable[V]], Variable[R]]` for 1st positional only parameter to call `vmap` but got `typing.Callable(first)[[Named(t, Tuple[Variable[F], Variable[S]])], Variable[F]]`.

Additional context

  • make t positional-only (def first(t, Tuple[F, S], /)) does not help
  • f is actually NOT positional ONLY

Is this a bug or limitation of pyre? Is there some way to tell pyre about the substitution, or am I missing something else?

rohori avatar Nov 22 '21 01:11 rohori

I think this is probably a bug in pyre, the code looks correct to me.

My guess is that it has to do with the handling of type variables, rather than named-vs-positional-only arguments, but until we find the root cause it's hard to say.

I'll put a task in our backlog to look at this. Thanks for the bug report!

stroxler avatar Dec 13 '21 01:12 stroxler