Type inference of compose with generic functions fails
suned opened this issue · 0 comments
suned commented
E.g
from typing import TypeVar
from pfun import compose
A = TypeVar('A')
def f(a: A) -> A:
pass
def g(a: int) -> str:
pass
compose(f, g) # error: Cannot infer argument 1 of compose
I think this is a current limitation of the mypy inference, since this also does not work:
R1 = TypeVar('R1')
R2 = TypeVar('R2')
R3 = TypeVar('R3')
def compose(f: Callable[[R2], R1], g: Callable[[R3], R2]) -> Callable[[R3], R1]:
pass
A = TypeVar('A')
def f(a: A) -> A:
pass
def g(a: int) -> str:
pass
compose(f, g) # error: Cannot infer type of argument 1 of compose