Skip to content

Reimplement TypedDict in a similar way to Python - #191

Merged
JelleZijlstra merged 23 commits into
python:mainfrom
JelleZijlstra:tdtests
Jun 9, 2023
Merged

Reimplement TypedDict in a similar way to Python#191
JelleZijlstra merged 23 commits into
python:mainfrom
JelleZijlstra:tdtests

Conversation

@JelleZijlstra

Copy link
Copy Markdown
Member

No description provided.

@JelleZijlstra

Copy link
Copy Markdown
MemberAuthor

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
Copy Markdown
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.

@JelleZijlstraJelleZijlstra changed the title Backport new is_typeddict testsReimplement TypedDict in a similar way to PythonMay 26, 2023
@JelleZijlstra

Copy link
Copy Markdown
MemberAuthor

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.

@AlexWaygoodAlexWaygood 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.

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

Comment threaddoc/index.rst Outdated
Comment threaddoc/index.rst Outdated
Comment threadCHANGELOG.md Outdated
Comment threadsrc/typing_extensions.py
Comment threadsrc/typing_extensions.py Outdated
JelleZijlstraand 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
Copy Markdown
MemberAuthor

All green now!

@AlexWaygoodAlexWaygood 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.

Looks great!

Comment threaddoc/index.rst Outdated
JelleZijlstraand 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:mainJun 9, 2023
@JelleZijlstra
JelleZijlstra deleted the tdtests branch June 9, 2023 14:34
Sign up for freeto 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

@JelleZijlstra@AlexWaygood