Skip to content

Forbid specialization of TypedDict types #92106

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Closed
serhiy-storchaka opened this issue May 1, 2022 · 1 comment
Closed

Forbid specialization of TypedDict types #92106

serhiy-storchaka opened this issue May 1, 2022 · 1 comment
Labels
topic-typing type-feature A feature request or enhancement

Comments

@serhiy-storchaka
Copy link
Member

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.

@JelleZijlstra
Copy link
Member

Closing since we merged #92176.

miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 2, 2022
…cts (pythonGH-92176)

(cherry picked from commit 81fb354)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington pushed a commit to miss-islington/cpython that referenced this issue May 2, 2022
…cts (pythonGH-92176)

(cherry picked from commit 81fb354)

Co-authored-by: Serhiy Storchaka <[email protected]>
miss-islington added a commit that referenced this issue May 3, 2022
miss-islington added a commit that referenced this issue May 3, 2022
hello-adam pushed a commit to hello-adam/cpython that referenced this issue Jun 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
topic-typing type-feature A feature request or enhancement
Projects
None yet
Development

Successfully merging a pull request may close this issue.

2 participants