Skip to content

Commit c662aa6

Browse files
authored
Merge branch 'main' into pep-11/demote-intel-darwin
2 parents 549febf + fb52d45 commit c662aa6

File tree

2 files changed

+40
-8
lines changed

2 files changed

+40
-8
lines changed

peps/pep-0728.rst

Lines changed: 36 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,13 @@ Title: TypedDict with Typed Extra Items
33
Author: Zixuan James Li <p359101898@gmail.com>
44
Sponsor: Jelle Zijlstra <jelle.zijlstra@gmail.com>
55
Discussions-To: https://discuss.python.org/t/pep-728-typeddict-with-typed-extra-items/45443
6-
Status: Draft
6+
Status: Accepted
77
Type: Standards Track
88
Topic: Typing
99
Created: 12-Sep-2023
1010
Python-Version: 3.15
1111
Post-History: `09-Feb-2024 <https://discuss.python.org/t/pep-728-typeddict-with-typed-extra-items/45443>`__,
12+
Resolution: `15-Aug-2025 <https://discuss.python.org/t/pep-728-typeddict-with-typed-extra-items/45443/159>`__
1213

1314

1415
Abstract
@@ -123,6 +124,24 @@ Given the usage of pre-:pep:`692` type annotation for ``**kwargs`` in existing
123124
codebases, it will be valuable to accept and type extra items on TypedDict so
124125
that the old typing behavior can be supported in combination with ``Unpack``.
125126

127+
Previous Discussions
128+
--------------------
129+
130+
The new features introduced in this PEP would address several long-standing feature
131+
requests in the type system. Previous discussions include:
132+
133+
- `Mypy issue <https://github.com/python/mypy/issues/7981>`__ asking for a "final TypedDict"
134+
(2019). While the discussion focuses on the ``@final`` decorator, the underlying feature request
135+
would be addressed by this PEP.
136+
- `Mailing list thread <https://mail.python.org/archives/list/typing-sig@python.org/thread/66RITIHDQHVTUMJHH2ORSNWZ6DOPM367/>`__
137+
asking for a way to say that a ``TypedDict`` can contain arbitrary extra keys (2020).
138+
- `Discussion <https://discuss.python.org/t/pep-692-using-typeddict-for-more-precise-kwargs-typing/17314/87>`__
139+
about an extension of the ``Unpack`` mechanism introduced by :pep:`692` (2023).
140+
- `PEP 705 <https://discuss.python.org/t/pep-705-typeddict-read-only-and-other-keys/36457>`__ in an earlier
141+
draft proposed a similar feature (2023); it was removed to keep that PEP simpler.
142+
- `Discussion <https://discuss.python.org/t/do-we-want-an-exact-typeddict-if-so-how-final-extras-never/44418>`__
143+
about an "exact" ``TypedDict`` (2024).
144+
126145
Rationale
127146
=========
128147

@@ -747,12 +766,22 @@ valid definition that indicates all extra items must be ``None``.)
747766
How to Teach This
748767
=================
749768

750-
The choice of the spelling ``"extra_items"`` is intended to make this
751-
feature more understandable to new users compared to shorter alternatives like
752-
``"extra"``.
753-
754-
Details of this should be documented in both the typing spec and the
755-
:mod:`typing` documentation.
769+
The new features introduced in this PEP can be taught together with the concept
770+
of inheritance as it applies to ``TypedDict``. A possible outline could be:
771+
772+
- Basics of ``TypedDict``: a ``dict`` with a fixed set of keys and value types.
773+
- ``NotRequired``, ``Required``, and ``total=False``: keys that may be missing.
774+
- ``ReadOnly``: keys that cannot be modified.
775+
- Inheritance: subclasses can add new keys. As a corollary, a value of a ``TypedDict``
776+
type may contain additional keys at runtime that are not specified in the type.
777+
- ``closed=True``: disallowing additional keys and restricting inheritance.
778+
- ``extra_items=VT``: allowing additional keys with a specified value type.
779+
780+
The concept of a closed ``TypedDict`` should also be cross-referenced in documentation
781+
for related concepts. For example, type narrowing with the ``in`` operator works
782+
differently, perhaps more intuitively, with closed ``TypedDict`` types. In addition, when ``Unpack``
783+
is used for keyword arguments, a closed ``TypedDict`` can be useful to restrict the
784+
allowed keyword arguments.
756785

757786
Backwards Compatibility
758787
=======================

peps/pep-0750.rst

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,7 @@ Author: Jim Baker <jim.baker@python.org>,
77
Lysandros Nikolaou <lisandrosnik@gmail.com>,
88
Dave Peck <davepeck@davepeck.org>
99
Discussions-To: https://discuss.python.org/t/71594
10-
Status: Accepted
10+
Status: Final
1111
Type: Standards Track
1212
Created: 08-Jul-2024
1313
Python-Version: 3.14
@@ -17,6 +17,9 @@ Post-History: `09-Aug-2024 <https://discuss.python.org/t/60408>`__,
1717
`18-Nov-2024 <https://discuss.python.org/t/71594>`__,
1818
Resolution: `10-Apr-2025 <https://discuss.python.org/t/71594/130>`__
1919

20+
.. canonical-doc:: :ref:`py3.14:template-strings`
21+
22+
2023
Abstract
2124
========
2225

0 commit comments

Comments
 (0)