returns
returns copied to clipboard
Consider adding `to_iterable` converter
After #244 we now have .from_iterable
constructor on every container.
We should also add to_iterable(container: Container[Sequence[T]]) -> Iterable[Container[T]]:
(where Container
is just an alias, we should support types for all existing containers).
So, this will allow us to construct and deconstruct values easily.
I am really tired for now. Let's move it to the next release.
We have a problem with HKT here, it can't convert Sequence[Kind1[_ContainerKind, _FirstType]]
to Sequence[Container[_FirstType]]
!
@kinded
def to_iterable(
container: KindN[
_ContainerKind, Sequence[_FirstType], _SecondType, _ThirdType
]
) -> Sequence[KindN[_ContainerKind, _FirstType, _SecondType, _ThirdType]]:
...
mypy output:
returns/converters.py:97: error: Value of type variable "_FunctionType" of "kinded" cannot be "Callable[[KindN[_ContainerKind, Sequence[_FirstType], _SecondType, _ThirdType]], Sequence[KindN[_ContainerKind, _FirstType, _SecondType, _ThirdType]]]"
Do you want to open an issue for this?
Ok, I see. @kinded
forces us to have KindN
as a return type. I think, that this is a correct behaviour. Not a bug.
Any ideas on how to support it?
I don't have any ideas 😞
Ok, we should change how @kinded
works in the future.
Because we can and will have cases when we need wrapped expressions like List[KindN[...]
.
Today I have tried to write Maybe[KindN[...]]
, but I was not able to do that. That's sad.
But, to fully support this, we need https://github.com/python/mypy/issues/9001 to be released.
I'm excited waiting for the next mypy
release, should be fixed at least three issues here hahaha