Skip to content

Fix TypedDict closed argument version check#21749

Open
vetrovk wants to merge 2 commits into
python:masterfrom
vetrovk:fix/typeddict-closed-version
Open

Fix TypedDict closed argument version check#21749
vetrovk wants to merge 2 commits into
python:masterfrom
vetrovk:fix/typeddict-closed-version

Conversation

@vetrovk

@vetrovk vetrovk commented Jul 19, 2026

Copy link
Copy Markdown

Summary

  • Reject the closed argument on typing.TypedDict when targeting Python versions below 3.15.
  • Preserve support through typing_extensions.TypedDict on older Python versions.
  • Cover both class and functional TypedDict syntax.

Details

PEP 728 adds the closed argument to the standard-library TypedDict in Python 3.15. Mypy previously accepted the argument for earlier target versions and applied closed TypedDict semantics without reporting that the runtime API was unavailable.

This change adds a semantic version check specifically for typing.TypedDict. Both closed=True and closed=False are rejected below Python 3.15, while the backport in typing_extensions remains supported.

Tests

  • python runtests.py check-typeddict
  • python -m pytest -n0 mypy/test/testcheck.py -k TypedDict
  • python runtests.py lint

Fixes #21747

AI-assisted: tooling was used during investigation and implementation; the contributor reviewed and validated the final patch.

@github-actions

This comment has been minimized.

@github-actions

Copy link
Copy Markdown
Contributor

Diff from mypy_primer, showing the effect of this PR on open source code:

altair (https://github.com/vega/altair)
+ altair/vegalite/v6/schema/_config.py:6593: error: "closed" argument to TypedDict is only available in Python 3.15 and later  [misc]
+ altair/vegalite/v6/schema/_config.py:6618: error: "closed" argument to TypedDict is only available in Python 3.15 and later  [misc]

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.

closed=True should not be supported for Python <3.15

1 participant