FazBrowse GitHub Viewer | Trending |
URL:
| Home
Tools: [Download Repo ZIP]   [Original HTTPS Page]

gh-92106: Forbid specialization of TypedDict types by serhiy-storchaka · Pull Request #92116 · python/cpython · GitHub

Repository navigation

gh-92106: Forbid specialization of TypedDict types - #92116

Closed
serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:typing-typeddict-non-generic
Closed

serhiy-storchaka wants to merge 1 commit into
python:mainfrom
serhiy-storchaka:typing-typeddict-non-generic

Conversation

Copy link
Copy Markdown
Member

Closes #92106.

Copy link
Copy Markdown
Member

Cc. @davidfstr

AlexWaygood left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Seems nice and simple, and it does indeed make no sense from a typing perspective to try to parameterise a non-generic TypedDict

Copy link
Copy Markdown
Member

This could break users who want to use generic TypedDicts compatible with pre-3.11:

if TYPE_CHECKING:
    class TD(TypedDict, Generic[T]):
        a: T
else:
    class TD(TypedDict):
        a: T

d: TD[int] = {"a": 1}

I think it's safer to keep things unchanged here.

Copy link
Copy Markdown
Contributor

I think it's safer to keep things unchanged here.

Agreed.

Also, this PR appears to conflict with #27663 , which seems likely to be merged soon.

Copy link
Copy Markdown
Member Author

Forbidding parametrization of non-generic TypedDict types is a side effect of #27663. I created a separate issue to make it clear.

If we agree that it should forbidden, we should merge this PR (which also includes tests). If we agree that it should be allowed, we should add other tests, explicitly document this behavior, and change #27663 to keep non-generic TypedDict types parametrizable.

Copy link
Copy Markdown
Member Author

This could break users who want to use generic TypedDicts compatible with pre-3.11:

Why not write if TYPE_CHECKING or sys.version_info >= (3, 11):?

Copy link
Copy Markdown
Member

This could break users who want to use generic TypedDicts compatible with pre-3.11:

Why not write if TYPE_CHECKING or sys.version_info >= (3, 11):?

That would work, but it would be a backward compatibility break. We should let code work on 3.11 unchanged if possible.

JelleZijlstra left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Choose a reason Spam Abuse Off Topic Outdated Duplicate Resolved Low Quality

Let's instead test that subscription works on arbitrary TypedDicts.

Copy link
Copy Markdown

When you're done making the requested changes, leave the comment: I have made the requested changes; please review again.

And if you don't make the requested changes, you will be poked with soft cushions!

Copy link
Copy Markdown
Member

Closing in favor of #92176.

serhiy-storchaka deleted the typing-typeddict-non-generic branch July 1, 2026 17:11
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters. Learn more about bidirectional Unicode characters
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

awaiting changes topic-typing type-feature A feature request or enhancement

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Forbid specialization of TypedDict types

5 participants


Back | FazBrowse Home | New Git URL