pfun icon indicating copy to clipboard operation
pfun copied to clipboard

Type inference of compose with generic functions fails

Open suned opened this issue 6 years ago • 0 comments

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

suned avatar Sep 15 '19 13:09 suned