[Python] Variadic generic type for python's TypedDict?

Discussão em 'Python' iniciado por Stack, Dezembro 22, 2024.

  1. Stack

    Stack Membro Participativo

    I'd like to do something like:

    from typing import TypeVar, Generic, TypedDict

    T = TypeVar("T")

    class Foo(Generic[T], TypedDict):
    bar: T
    ...

    foo: Foo[int] = {"bar": 42}


    But this yields a type error ("cannot inherit from both a TypedDict and a non-TypedDict base class").

    Are there any ways to achieve this result?

    Continue reading...

Compartilhe esta Página