Skip to content

Fix TypedDict closed argument version check#21749

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

Fix TypedDict closed argument version check#21749
vetrovk wants to merge 4 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

This comment has been minimized.

@A5rocks A5rocks left a comment

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Sorry but this change doesn't really work. And as mentioned in the issue, this should be allowed in stub files/typing only sections.

Please do not respond with LLM-generated comments, or I will assume you are putting no work into this PR and close it.

Comment thread mypy/semanal_typeddict.py
base_fullname = defn.base_type_exprs[0].fullname

is_closed: bool | None = None
if "closed" in defn.keywords:

Copy link
Copy Markdown
Collaborator

Choose a reason for hiding this comment

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

Why can't you do the check here...?

@github-actions

This comment has been minimized.

@vetrovk

vetrovk commented Jul 20, 2026

Copy link
Copy Markdown
Author

Thanks for the review. The issue is now addressed.

@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

2 participants