pyre-check
pyre-check copied to clipboard
Incompatible parameter type: Expected typing.Callable
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
tpositional-only (def first(t, Tuple[F, S], /)) does not help fis 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?
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!