dry-python / returns

Make your functions return something meaningful, typed, and safe!
https://returns.rtfd.io
BSD 2-Clause "Simplified" License
3.54k stars 116 forks source link

Kind of Kind #813

Open horta opened 3 years ago

horta commented 3 years ago

Bug report

What's wrong

I would like to do

from __future__ import annotations

from typing import TypeVar
from returns.primitives.hkt import Kind1, Kind2

class Alphabet:
    pass

_A = TypeVar("_A", bound=Alphabet)

class State(Kind1["State", _A]):
    pass

_S = TypeVar("_S", bound=State)

class Step(Kind2["Step", _A, _S]):
    def foo(self, step: Step[_A, Kind1[_S, _A]]): # mypy error
        del step
        del self
        pass

Such that the step parameter of Step.foo has the type-hint Step[_A, _S[_A]].

kind

System information

horta commented 3 years ago

I have just tried

kind2

Was that supposed to work?

sobolevn commented 3 years ago

Nested kinds are not supported at the moment 😢

horta commented 3 years ago

I figured. This is an improvement then but I wonder if it is worth the work.

sobolevn commented 3 years ago

I have some use-cases when this would be a good thing to have. It really depends on how much time / effort / hacks are required to make it work.