Skip to content

gh-92106: Forbid specialization of TypedDict types #92116

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

Conversation

serhiy-storchaka
Copy link
Member

Closes #92106.

@AlexWaygood
Copy link
Member

Cc. @davidfstr

Copy link
Member

@AlexWaygood AlexWaygood left a comment

Choose a reason for hiding this comment

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

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

@JelleZijlstra
Copy link
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.

@davidfstr
Copy link
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.

@serhiy-storchaka
Copy link
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.

@serhiy-storchaka
Copy link
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):?

@JelleZijlstra
Copy link
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.

Copy link
Member

@JelleZijlstra JelleZijlstra left a comment

Choose a reason for hiding this comment

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

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

@bedevere-bot
Copy link

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!

@JelleZijlstra
Copy link
Member

Closing in favor of #92176.

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