mypy error for HKT example from docs
vchernetskyi993 opened this issue · 5 comments
Bug report
I was going through your documentation and stumbled upon an issue in HKT example: https://returns.readthedocs.io/en/latest/pages/hkt.html#id1.
What's wrong
Trying out your to_str
definition:
from typing import TypeVar
from returns.maybe import Maybe
from returns.primitives.hkt import Kind1, kinded
from returns.interfaces.container import Container1, ContainerN
T = TypeVar("T", bound=Container1)
@kinded
def to_str(container: Kind1[T, int]) -> Kind1[T, str]:
return container.map(str)
reveal_type(to_str(Maybe.from_value(1)))
Produces mypy
error: Value of type variable "T" of "to_str" cannot be "Maybe[Any]" [type-var]
.
Playing around, I found, that replacing Container1
with ContainerN
fixes the issue (why?).
T = TypeVar("T", bound=ContainerN)
How is that should be
Examples from the documentation should work :)
I'm not sure whether this is a defect, maybe I'm doing something wrong, but before submitting this one I've rechecked that my code matches the docs closely.
System information
python
version: 3.11.1returns
version: 0.20.0mypy
version: 1.3.0- I'm using config from here: https://github.com/wemake-services/wemake-python-styleguide/blob/master/styles/mypy.toml
Yes, makes sense. Can you please send a PR? :)
Uh-oh, need to investigate the issue more for this.
We want T = TypeVar("T", bound=Container1)
to work without an error, correct?
ContainerN
is always fine
Basically, Container1
won't exist soon.
Understood, thanks! Will create small PR for docs tomorrow.