suned/pfun

Type inference fails when using generic Reader alias

suned opened this issue · 1 comments

suned commented
from pfun.reader import Reader
from typing import TypeVar

A = TypeVar('A')
Action = Reader[str, A]
reveal_type(Action(lambda _: True))  # Revealed type is 'pfun.reader.Reader[builtins.str*, Any]'

This is probably due to a bug in mypy. At least the following also fails:

from typing import TypeVar, Generic, Callable

A = TypeVar('A')
B = TypeVar('B')
class C(Generic[A, B]):
    def __init__(self, f: Callable[[A], B]):
        pass
C = TypeVar('C')
Alias = C[str, C]
reveal_type(Alias(lambda _: True))  # Revealed type is 'C[builtins.str*, Any]'
suned commented

After trampolining Reader, this issue is far less relevant since constructing readers with the raw constructor is discouraged in favour of using value.