Skip to content
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

Reimplement TypedDict in a similar way to Python #191

Merged
merged 23 commits into from
Jun 9, 2023

Conversation

JelleZijlstra
Copy link
Member

No description provided.

@JelleZijlstra
Copy link
Member Author

Seems like TypedDict is implemented somewhat differently on CPython and in typing-extensions: on CPython it's a function, here it's a class and an instance of _TypedDictMeta. Maybe we should follow the CPython version more, which would mean concretely that is_typeddict(TypedDict) would be false and typing_extensions.TypedDict would no longer be a type.

@AlexWaygood
Copy link
Member

Conceptually, it's better for TypedDict to be a function rather than a class, because it's a factory for creating new types, rather than a factory for creating instances of a specific type. I believe that's why the change was made over at CPython to change NamedTuple and TypedDict so that they're functions rather than classes.

@JelleZijlstra JelleZijlstra changed the title Backport new is_typeddict tests Reimplement TypedDict in a similar way to Python May 26, 2023
@JelleZijlstra
Copy link
Member Author

TypedDict now closely follows the implementation and tests in Python main, except for some interesting workarounds to get generics to work, and a few other details that don't work in old versions.

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.

Looks good! Haven't reviewed the tests in depth, but I trust you're testing everything that's tested in CPython?

Looks like a few tests are failing on py312 btw

doc/index.rst Outdated Show resolved Hide resolved
doc/index.rst Outdated Show resolved Hide resolved
CHANGELOG.md Outdated Show resolved Hide resolved
src/typing_extensions.py Show resolved Hide resolved
src/typing_extensions.py Outdated Show resolved Hide resolved
JelleZijlstra and others added 4 commits May 26, 2023 08:58
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstra
Copy link
Member Author

All green now!

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.

Looks great!

doc/index.rst Outdated Show resolved Hide resolved
JelleZijlstra and others added 2 commits May 26, 2023 17:23
Co-authored-by: Alex Waygood <Alex.Waygood@Gmail.com>
@JelleZijlstra JelleZijlstra merged commit d826561 into python:main Jun 9, 2023
@JelleZijlstra JelleZijlstra deleted the tdtests branch June 9, 2023 14:34
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.

2 participants