Skip to content

Forbid specialization of TypedDict types #92106

@serhiy-storchaka

Description

@serhiy-storchaka

typing.TypedDict creates a dict subclass. dict is a generic class, and can be specialized, e.g. dict[int, str]. But TypedDict creates a specialized dictionary class, with different types for values for different keys (and the type of the key is always str). It is not a generic class. It does not make sense to specialize it the same way as TypedDict.

class Point2D(TypedDict):
    x: int
    y: int
    label: str

Point2D[int, str]

The last line should be error at run time.

Generic TypedDict (#89026) is a different story.

This change can be made as a side effect of #27663, but I prefer to have a separate discussion for this.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions