GV

GeezerVison

The World Wide Web, restored to 800 pixels of glory.

Home|About|Gaming cabinet|Archives|How it works|Starter sites

On this site

  • Sign in
  • ActionsCI/CD and automation
  • CodespacesCloud development environments
  • All Features
  • Documentation
  • Training
  • Certifications
  • Build with Copilot
  • Customize Copilot
  • Integrations
  • Trending repos
  • GitHub Sponsors
  • Developer articles
  • Enterprises

This view

  • Original page
  • New address

GeezerVison is showing github.com — Implement support for closed TypedDicts (PEP 728) by alicederyn · Pull Request #21382 · python/mypy

Implement support for closed TypedDicts (PEP 728) #21382

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.

Sign up for GitHub

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
ilevkivskyi merged 43 commits into python:master from alicederyn:closed.keyword
Jun 2, 2026

Uh oh!

There was an error while loading. Please reload this page.

Merged

Implement support for closed TypedDicts (PEP 728) #21382

Changes from 1 commit
Commits
Show all changes
43 commits
Select commit Hold shift + click to select a range
fa59235
Support nested special forms in functional syntax
alicederyn Apr 29, 2026
c06fef7
Subtypes fix: required keys must remain required
alicederyn Apr 22, 2026
4a82d3c
Meet fix: mutable keys must remain mutable
alicederyn Apr 22, 2026
ca099f4
Improve TypedDict meet
alicederyn Apr 22, 2026
f79ba70
Join fix: readonly keys must remain readonly
alicederyn Apr 22, 2026
2ed7992
Improve TypedDict join
alicederyn Apr 22, 2026
ab1a151
Expand TypedDict subclassing tests
alicederyn May 1, 2026
e626c19
Support type refinement in TypedDict subclasses
alicederyn May 1, 2026
d8c619d
Fix TypeAnalyser to retain readonly keys
alicederyn Apr 30, 2026
e7372e4
Narrow on explicitly uninhabited keys
alicederyn Apr 30, 2026
c7115c1
Support parsing TypedDict closed keyword
alicederyn Apr 23, 2026
bce4b17
Implement closed support in TypedDict subtyping
alicederyn Apr 27, 2026
90cb21f
Implement closed support in subclassing
alicederyn Apr 24, 2026
4106525
Implement closed support in join logic
alicederyn Apr 28, 2026
6cc0d63
Implement closed support in meet logic
alicederyn Apr 29, 2026
5bfcc43
Implement closed support in narrowing
alicederyn Apr 30, 2026
d7449df
Implement TypeVar support in narrowing
alicederyn Apr 30, 2026
2621704
Implement closed support in astdiff
alicederyn Apr 30, 2026
34a13de
Implement closed support in stubgen
alicederyn Apr 30, 2026
87ede99
Implement closed support in serialization
alicederyn Apr 30, 2026
bbdd827
Implement closed support in TypeAnalyser
alicederyn Apr 30, 2026
c1ff8b3
Implement closed support in unpacking
alicederyn Apr 30, 2026
ca5a13f
Implement closed support in expandtype
alicederyn May 1, 2026
4d3a7b0
Implement closed support in get method
alicederyn May 1, 2026
877e000
Merge branch 'master' into closed.keyword
alicederyn May 19, 2026
6f3291b
Fix bug with join and Any
alicederyn May 19, 2026
776eb10
Fix bug with meet and Any
alicederyn May 19, 2026
05d3a4b
Refactor common logic into zipall
alicederyn May 19, 2026
022a501
Fix assumption that missing items are ReadOnly
alicederyn May 19, 2026
bd05e88
Allow adding Never items to closed subtypes
alicederyn May 19, 2026
d102505
Reword not-required compatibility error messages
alicederyn May 19, 2026
9279a01
Test case from no error to error
alicederyn May 19, 2026
2d1333c
Delay subtype validation to TypeChecker
alicederyn May 18, 2026
4ee7856
Add closed keyword to TypedDict docs
alicederyn May 20, 2026
8bcc243
Store validation information in TypeInfo
alicederyn May 26, 2026
77e8a59
Link TypedDict branch narrowing to test cases
alicederyn May 26, 2026
4261abb
Remove references to 'MRO'
alicederyn May 26, 2026
8d92a10
Extend subclass tests with subtype checks
alicederyn May 26, 2026
37481a2
Merge branch 'master' into closed.keyword
alicederyn May 26, 2026
42ec16f
Manually wrap strings/comments
alicederyn Jun 1, 2026
5cbb687
Remove unnecessary extra newline
alicederyn Jun 1, 2026
31b5045
Document new TypedDict inheritance rules
alicederyn Jun 1, 2026
fbd2818
Merge branch 'master' into closed.keyword
alicederyn Jun 2, 2026
File filter
Filter by extension

Clear filters
Conversations
Failed to load comments.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Jump to
Jump to file
Failed to load files.
Loading

Uh oh!

There was an error while loading. Please reload this page.

Diff view
Diff view
Prev Previous commit
Next Next commit
Remove references to 'MRO'
We are only looking at immediate bases, so 'MRO' is misleading. Revert
to previous framing as just "reverse order".
  • Loading branch information

Uh oh!

There was an error while loading. Please reload this page.

@alicederyn
alicederyn committed May 26, 2026
commit 4261abb8235ce1baeaf71cdbff4e729a0d4476e9

Some comments aren't visible on the classic Files Changed page.

There are no files selected for viewing

10 changes: 5 additions & 5 deletions 10 mypy/semanal_typeddict.py
Show comments
View file
Open in desktop
Original file line number Diff line number Diff line change
Expand Up @@ -233,7 +233,7 @@ def fetch_keys_and_types_from_base(

return info, valid_items

def field_sources_in_reverse_mro(
def field_sources_in_reverse_order(
self,
bases: list[tuple[TypeInfo, dict[str, Type]]],
child_field_sources: dict[str, FieldSource],
Expand All @@ -260,9 +260,9 @@ def field_sources_in_reverse_mro(
return result

def primary_source(self, sources: list[FieldSource]) -> FieldSource:
"""Select a primary source from a reverse-MRO-ordered list of sources.
"""Select a primary source from a reverse-ordered list of sources.

The primary source will be the last in the MRO list, skipping readonly
The primary source will be the last in the list, skipping readonly
base class sources unless they are the only available option.
"""
if not sources[-1].base:
Expand Down Expand Up @@ -331,7 +331,7 @@ def resolve_field_inheritance(
ctx: Context,
) -> tuple[dict[str, Type], set[str], set[str], bool, dict[str, TypedDictFieldSource]]:
"""Determine field types, requiredness, readonlyness, and closedness."""
field_sources = self.field_sources_in_reverse_mro(bases, child_field_sources, ctx)
field_sources = self.field_sources_in_reverse_order(bases, child_field_sources, ctx)
field_types: dict[str, Type] = {}
chosen_sources: dict[str, TypedDictFieldSource] = {}
required_keys: set[str] = set()
Expand All @@ -355,7 +355,7 @@ def resolve_field_inheritance(
# is unlikely to produce a tight enough result. We could check all the
# candidates from the base classes, but it would be O(n^2) complexity
# to find out which is a supertype of all the others. Instead, use the
# first definition in MRO order, and let the user provide the correct
# first definition we encounter, and let the user provide the correct
# definition in the subclass if this fails.
Comment thread

@ilevkivskyi ilevkivskyi May 29, 2026

Copy link
Copy Markdown
Member

There was a problem hiding this comment.

Choose a reason for hiding this comment

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

This behavior is worth documenting (with a short example). It is not obvious to a user which base takes precedence: first or last.

Sorry, something went wrong.

Uh oh!

There was an error while loading. Please reload this page.

alicederyn reacted with thumbs up emoji
All reactions
  • 👍 1 reaction
field_types[field_name] = primary_source.field_type
chosen_sources[field_name] = TypedDictFieldSource(
Expand Down
Add this suggestion to a batch that can be applied as a single commit. This suggestion is invalid because no changes were made to the code. Suggestions cannot be applied while the pull request is closed. Suggestions cannot be applied while viewing a subset of changes. Only one suggestion per line can be applied in a batch. Add this suggestion to a batch that can be applied as a single commit. Applying suggestions on deleted lines is not supported. You must change the existing code in this line in order to create a valid suggestion. Outdated suggestions cannot be applied. This suggestion has been applied or marked resolved. Suggestions cannot be applied from pending reviews. Suggestions cannot be applied on multi-line comments. Suggestions cannot be applied while the pull request is queued to merge. Suggestion cannot be applied right now. Please check back later.
You are visitor 01402792 — GeezerVison does not store the pages you look up.
Best viewed with Netscape Navigator 4.7 or Internet Explorer 6 at 800×600. No cookies required.