@@ -17,7 +17,7 @@ TypedDict types can define any number of :term:`items <item>`, which are string
1717keys associated with values of a specified type. For example,
1818a TypedDict may contain the item ``a: str ``, indicating that the key ``a ``
1919must map to a value of type ``str ``. Items may be either :term: `required `,
20- meaning they must be present in any instance of the TypedDict type, or
20+ meaning they must be present in every instance of the TypedDict type, or
2121:term: `non-required `, meaning they may be omitted, but if they are present,
2222they must be of the type specified in the TypedDict definition. By default,
2323all items in a TypedDict are mutable, but items
@@ -395,14 +395,19 @@ is inherited from its superclass by default::
395395 pass
396396
397397However, subclasses may also explicitly use the ``closed `` and ``extra_items `` arguments
398- to change the openness of the TypedDict, but in some cases this yields a type checker error.
399- If the base class is open, all possible states are allowed in the subclass: it may remain open,
400- it may be closed (with ``closed=True ``), or it may have extra items (with ``extra_items=... ``).
401- If the base class is closed, any child classes must also be closed.
402- If the base class has extra items, but they are not read-only, the child class must also allow
403- the same extra items. If the base class has read-only extra items, the child class may be closed,
404- or it may redeclare its extra items with a type that is :term: `assignable ` to the base class type.
405- Child classes may also have mutable extra items if the base class has read-only extra items.
398+ to change the openness of the TypedDict, but in some cases this yields a type checker error:
399+
400+ - If the base class is open, all possible states are allowed in the subclass: it may remain open,
401+ it may be closed (with ``closed=True ``), or it may have extra items (with ``extra_items=... ``).
402+
403+ - If the base class is closed, any child classes must also be closed.
404+
405+ - If the base class has extra items, but they are not read-only, the child class must also allow
406+ the same extra items.
407+
408+ - If the base class has read-only extra items, the child class may be closed,
409+ or it may redeclare its extra items with a type that is :term: `assignable ` to the base class type.
410+ Child classes may also have mutable extra items if the base class has read-only extra items.
406411
407412For example::
408413
@@ -607,6 +612,7 @@ A TypedDict type is a subtype of ``dict[str, VT]`` if the following conditions a
607612
608613- The TypedDict type has mutable :term: `extra items ` of a type that is :term: `equivalent ` to ``VT ``.
609614- All items on the TypedDict satisfy the following conditions:
615+
610616 - The value type of the item is :term: `equivalent ` to ``VT ``.
611617 - The item is not read-only.
612618 - The item is not required.
@@ -627,7 +633,7 @@ For example::
627633 regular_dict: dict[str, int] = not_required_num_dict # OK
628634 f(not_required_num_dict) # OK
629635
630- In this case, methods that are previously unavailable on a TypedDict are allowed,
636+ In this case, some methods that are otherwise unavailable on a TypedDict are allowed,
631637with signatures matching ``dict[str, VT] ``
632638(e.g.: ``__setitem__(self, key: str, value: VT) -> None ``)::
633639
@@ -742,15 +748,15 @@ This section discusses some specific operations in more detail.
742748 if the string value of ``e `` cannot be determined statically.
743749 (This simplifies to ``object `` if ``d `` is :term: `open `.)
744750
745- * ``clear() `` is not safe on :term: `open ` TypedDicts since it could remove required keys , some of which
751+ * ``clear() `` is not safe on :term: `open ` TypedDicts since it could remove required items , some of which
746752 may not be directly visible because of :term: `structural `
747753 :term: `assignability <assignable> `. However, this method is safe on
748754 :term: `closed ` TypedDicts and TypedDicts with :term: `extra items ` if
749755 there are no required or read-only items and there cannot be any subclasses with required
750756 or read-only items.
751757
752758* ``popitem() `` is similarly unsafe on many TypedDicts, even
753- if all known keys are not required (`` total=False ``) .
759+ if all known items are :term: ` non- required` .
754760
755761* ``del obj['key'] `` should be rejected unless ``'key' `` is a
756762 non-required, mutable key.
@@ -785,14 +791,14 @@ This section discusses some specific operations in more detail.
785791* The ``update() `` method should not allow mutating a read-only item.
786792 Therefore, type checkers should error if a
787793 TypedDict with a read-only item is updated with another TypedDict that declares
788- that key ::
794+ that item ::
789795
790796 class A(TypedDict):
791797 x: ReadOnly[int]
792798 y: int
793799
794- a1: A = { "x": 1, "y": 2 }
795- a2: A = { "x": 3, "y": 4 }
800+ a1: A = {"x": 1, "y": 2}
801+ a2: A = {"x": 3, "y": 4}
796802 a1.update(a2) # Type check error: "x" is read-only in A
797803
798804 Unless the declared value is of bottom type (:data: `~typing.Never `)::
0 commit comments