Skip to content

Support generic NamedTuples #685

Closed
@ghost

Description

I tried this for a generic NamedTuple:

S = TypeVar("S")
T = TypeVar("T")

class Pair(Generic[S, T],
    NamedTuple("Pair",[
        ('fst', S),
        ('second', T)])):
    def show(self):
        print(self.fst, self.second)

p = Pair("ab", 22)  # type: Pair[str, int]

Mypy raised an exception: RuntimeError: TypeVarType is already analysed.

Related question: is this the right way to define a generic NamedTuple?

Thanks!

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions