Skip to content

Feature request: Allow unpacking of type variable bound to typed dict #1399

Open
@NeilGirdhar

Description

@NeilGirdhar

I'd like to have a family of classes where overrides have additional parameters to various methods:

from typing import Generic, Unpack

from typing_extensions import TypedDict, TypeVar, override


class EmptyDict(TypedDict, total=True):
    pass


Extra = TypeVar('Extra', bound=TypedDict, default=EmptyDict)


class C(Generic[Extra]):
    def f(self, **kwargs: Unpack[Extra]) -> None:  # error: Expected TypedDict type argument for Unpack (reportGeneralTypeIssues)
        pass


class D(C):
    @override
    def f(self) -> None:  # error: Method "f" overrides class "C" in an incompatible manner
        pass


class HasName(TypedDict, total=True):
    name: str


class E(C[HasName]):
    @override
    def f(self, name: str) -> None:  # This doesn't work.
        print(name)



D().f()
E().f("a")

See @erictraut's instructive comment on the issue here.

Metadata

Metadata

Assignees

No one assigned

    Labels

    topic: featureDiscussions about new features for Python's type annotations

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions