Skip to content

Add spec and tests for PEP 728 #2068

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 6 commits into from
Aug 17, 2025
Merged

Conversation

JelleZijlstra
Copy link
Member

I mostly copied the spec from PEP 728, with light editing to remove references to "this PEP"
and fix links. In a followup I plan to reorganize the TypedDict spec.

The conformance tests primarily derive from the examples in the PEP.

I mostly copied the spec from PEP 728, with light editing to remove references to "this PEP"
and fix links. In a followup I plan to reorganize the TypedDict spec.

The conformance tests primarily derive from the examples in the PEP.
@@ -0,0 +1,139 @@
conformant = "Fail"
Copy link
Member

Choose a reason for hiding this comment

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

Suggested change
conformant = "Fail"
conformant = "Unsupported"

Copy link
Collaborator

@erictraut erictraut left a comment

Choose a reason for hiding this comment

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

Thanks for doing this!

@@ -0,0 +1,347 @@
# pyright: enableExperimentalFeatures=true
Copy link
Collaborator

Choose a reason for hiding this comment

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

This can be removed once pyright 1.1.404 is released.

``A`` if ``B`` is :term:`structurally <structural>` assignable to
``A``. This is true if and only if all of the following are satisfied:

* **[If no key with the same name can be found in ``B``, the 'extra_items'
Copy link
Collaborator

Choose a reason for hiding this comment

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

Is this rule meant to be bolded? Just wondering why it gets special emphasis.

Copy link
Member Author

Choose a reason for hiding this comment

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

It's because it's added to the previous rules; it's like this in the PEP. I'll clean this up when I rewrite the TypedDict spec in a followup.

JelleZijlstra and others added 2 commits August 16, 2025 09:04
Co-authored-by: Brian Schubert <brianm.schubert@gmail.com>
Co-authored-by: Rob Hand <146272+sinon@users.noreply.github.com>
JelleZijlstra added a commit to JelleZijlstra/typing that referenced this pull request Aug 17, 2025
This is an edit of the TypedDict spec for clarity and flow. My goal was to
unify the pieces of the spec that derive from the various PEPs into a coherent
whole. I removed excessive examples and motivations: the spec should specify,
not justify. The length of the spec chapter is reduced by more than half.

This change is on top of python#2068 (adding PEP 728).

The general approach I took is to first define the kinds of TypedDicts that
can exist, then explain the syntax for defining TypedDicts, then discuss
other aspects of TypedDict types.

I introduce some new terminology around PEP 728 to make it easier to talk
about the different kinds of TypedDict. TypedDicts are defined to have a
property called openness, which can have three states:
- Open: all TypedDicts prior to PEP 728
- Closed: no extra keys are allowed (closed=True)
- With extra items: extra_items=... from PEP 728

I retained existing text where it made sense but also wrote some from
scratch.
@JelleZijlstra JelleZijlstra merged commit b57e1ff into python:main Aug 17, 2025
3 checks passed
JelleZijlstra added a commit to JelleZijlstra/typing that referenced this pull request Aug 17, 2025
This is an edit of the TypedDict spec for clarity and flow. My goal was to
unify the pieces of the spec that derive from the various PEPs into a coherent
whole. I removed excessive examples and motivations: the spec should specify,
not justify. The length of the spec chapter is reduced by more than half.

This change is on top of python#2068 (adding PEP 728).

The general approach I took is to first define the kinds of TypedDicts that
can exist, then explain the syntax for defining TypedDicts, then discuss
other aspects of TypedDict types.

I introduce some new terminology around PEP 728 to make it easier to talk
about the different kinds of TypedDict. TypedDicts are defined to have a
property called openness, which can have three states:
- Open: all TypedDicts prior to PEP 728
- Closed: no extra keys are allowed (closed=True)
- With extra items: extra_items=... from PEP 728

I retained existing text where it made sense but also wrote some from
scratch.
facebook-github-bot pushed a commit to facebook/pyrefly that referenced this pull request Aug 17, 2025
Summary:
Updated conformance tests to pull in a few significant PRs:
* python/typing#2067 (a fair number of small tweaks)
* python/typing#2056 (new test file for dataclasses match_args)
* python/typing#2068 (new test file for TypedDict extra items)

Reviewed By: samwgoldman

Differential Revision: D80424920

fbshipit-source-id: 3d8ac3e70aa86329f0d1adb1af2d2e0837bc5c4e
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.

4 participants