Skip to content

Reimplement TypedDict in a similar way to Python #191

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 23 commits into from
Jun 9, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 6 additions & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
@@ -1,5 +1,11 @@
# Unreleased

- Align the implementation of `TypedDict` with the implementation in the
standard library on Python 3.9 and higher.
`typing_extensions.TypedDict` is now a function instead of a class. The
private functions `_check_fails`, `_dict_new`, and `_typeddict_new`
have been removed. `is_typeddict` now returns `False` when called with
`TypedDict` itself as the argument. Patch by Jelle Zijlstra.
- Declare support for Python 3.12. Patch by Jelle Zijlstra.
- Fix tests on Python 3.13, which removes support for creating
`TypedDict` classes through the keyword-argument syntax. Patch by
Expand Down
12 changes: 12 additions & 0 deletions doc/index.rst
Original file line number Diff line number Diff line change
Expand Up @@ -296,6 +296,12 @@ Special typing primitives

Support for the ``__orig_bases__`` attribute was added.

.. versionchanged:: 4.7.0

``TypedDict`` is now a function rather than a class.
This brings ``typing_extensions.TypedDict`` closer to the implementation
of :py:mod:`typing.TypedDict` on Python 3.9 and higher.

.. class:: TypeVar(name, *constraints, bound=None, covariant=False,
contravariant=False, infer_variance=False, default=...)

Expand Down Expand Up @@ -629,6 +635,12 @@ Functions

.. versionadded:: 4.1.0

.. versionchanged:: 4.7.0

:func:`is_typeddict` now returns ``False`` when called with
:data:`TypedDict` itself as the argument, consistent with the
behavior of :py:func:`typing.is_typeddict`.

.. function:: reveal_type(obj)

See :py:func:`typing.reveal_type`. In ``typing`` since 3.11.
Expand Down
6 changes: 5 additions & 1 deletion src/_typed_dict_test_helper.py
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
from __future__ import annotations

from typing import Generic, Optional, T
from typing_extensions import TypedDict
from typing_extensions import TypedDict, Annotated, Required


# this class must not be imported into test_typing_extensions.py at top level, otherwise
Expand All @@ -16,3 +16,7 @@ class Foo(TypedDict):

class FooGeneric(TypedDict, Generic[T]):
a: Optional[T]


class VeryAnnotated(TypedDict, total=False):
a: Annotated[Annotated[Annotated[Required[int], "a"], "b"], "c"]
Loading