Thanks to visit codestin.com
Credit goes to github.com

Skip to content

allow TypedDict as a type argument #614

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

Merged
merged 2 commits into from
Jun 3, 2025

Conversation

JelleZijlstra
Copy link
Member

@JelleZijlstra JelleZijlstra commented Jun 3, 2025

I tried some more creative solutions but couldn't get anything more concise to work.

Fixes #613.

@AlexWaygood AlexWaygood self-requested a review June 3, 2025 06:49
Copy link
Collaborator

@srittau srittau left a comment

Choose a reason for hiding this comment

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

I think one thing that would make this code a bit clearer is if we had a custom copy of _SpecialForm (that isn't recognized as such by the code typing.py, maybe called something like _UnrecognizedSpecialForm and documented) and derive from that. This would also make it easier to keep that "fake" special form in sync with the real typing._SpecialForm.

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.

We already vendor typing._SpecialForm here:

# Vendored from cpython typing._SpecialFrom
class _SpecialForm(typing._Final, _root=True):

If I move that higher up in the file (so it's defined before _TypedDictSpecialForm) and then make a one-line change so that _TypedDictSpecialForm inherits from _SpecialForm rather than _ExtensionsSpecialForm, all our tests pass and it fixes the issue reported.

This is what we already do to ensure that typing.Type[typing_extensions.Self] is accepted on older versions of Python.

@srittau
Copy link
Collaborator

srittau commented Jun 3, 2025

Could you also add a comment that this means that this _SpecialForm is not recognized by typing in some situations and that that is intended behavior?

@JelleZijlstra
Copy link
Member Author

Thank you! I missed that we already had a _SpecialForm class.

@JelleZijlstra JelleZijlstra merged commit d17c456 into python:main Jun 3, 2025
21 checks passed
@JelleZijlstra JelleZijlstra deleted the td-type-arg branch June 3, 2025 19:26
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

TypedDict removal causing breaking changes
3 participants