Closed phi-friday closed 11 months ago
As you can see in pep-646,
It is not possible to use type hints in a form such as tuple[Unpack[ArgsT], Unpack[OtherArgsT]]
.
But anyway, in pyright
, the type inference works fine (although it causes errors when define)
I think there's a better way, but I couldn't think of it right away, so I used Unpack
twice.
I wish there was another way.
As you can see in pep-646, It is not possible to use type hints in a form such as
tuple[Unpack[ArgsT], Unpack[OtherArgsT]]
.But anyway, in
pyright
, the type inference works fine (although it causes errors when define)I think there's a better way, but I couldn't think of it right away, so I used
Unpack
twice. I wish there was another way.
I fixed this problem, but when inferring the type of a particular function, it rely entirely on pyright. ex:
def _iter_unpack_tuples_1( # noqa: ANN202
value: tuple[Unpack[ArgsT]], # type: ignore[reportInvalidTypeVarUse]
other: tuple[Unpack[OtherArgsT]], # type: ignore[reportInvalidTypeVarUse]
):
return (*other, *value)
""" in pyright,
(function) def _iter_unpack_tuples_1(
value: tuple[*ArgsT@_iter_unpack_tuples_1],
other: tuple[*OtherArgsT@_iter_unpack_tuples_1]
) -> tuple[*OtherArgsT@_iter_unpack_tuples_1, *ArgsT@_iter_unpack_tuples_1]
"""
This looks really interesting 👏 Please give me some time to review since my bandwidth is currently a bit limited
As you can see in pep-646, It is not possible to use type hints in a form such as
tuple[Unpack[ArgsT], Unpack[OtherArgsT]]
. But anyway, inpyright
, the type inference works fine (although it causes errors when define) I think there's a better way, but I couldn't think of it right away, so I usedUnpack
twice. I wish there was another way.I fixed this problem, but when inferring the type of a particular function, it rely entirely on pyright. ex:
def _iter_unpack_tuples_1( # noqa: ANN202 value: tuple[Unpack[ArgsT]], # type: ignore[reportInvalidTypeVarUse] other: tuple[Unpack[OtherArgsT]], # type: ignore[reportInvalidTypeVarUse] ): return (*other, *value) """ in pyright, (function) def _iter_unpack_tuples_1( value: tuple[*ArgsT@_iter_unpack_tuples_1], other: tuple[*OtherArgsT@_iter_unpack_tuples_1] ) -> tuple[*OtherArgsT@_iter_unpack_tuples_1, *ArgsT@_iter_unpack_tuples_1] """
I thought it would be better to use lambda
, so I changed it to lambda
.
This looks really interesting 👏 Please give me some time to review since my bandwidth is currently a bit limited
@dbrattli Of course. Thank you for your interest.
I tried it, and it wasn't as useful or robust as I thought it would be.
how to use
TODO
type: ignore