Skip to content

Annotate Callable input params from a generic tuple #1462

Answered by hmc-cs-mdrissi
maciejzj asked this question in Q&A
Discussion options

You must be logged in to vote

Internal error always means bug in mypy and you can open an issue there.

There are multiple type checkers available. Pyright and pyre both have support for typevartuple and you can test your code with them.

Your code does have a few errors, but is close. Here's a fixed version that type checks with pyright,

from typing import Sequence, Callable, TypeVar, Generic, Unpack, TypeVarTuple

InT = TypeVarTuple("InT")
class Dataset(Generic[Unpack[InT]]):
    def __getitem__(self, idx: int) -> tuple[Unpack[InT]]:
        ...

class StrDs(Dataset[Unpack[tuple[str, str]]]):
    def __init__(self):
        self.d = [("1", "10"), ("2", "20"), ("3", "30")]

    def __getitem__(self, idx: int) -> tuple[str

Replies: 1 comment 2 replies

Comment options

You must be logged in to vote
2 replies
@maciejzj
Comment options

@hmc-cs-mdrissi
Comment options

Answer selected by maciejzj
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
3 participants