You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
Fixed the header levels in the "Read-only Items". (#1727)
Fixed the header levels in the "Read-only Items". Currently, the "Read-only Items" section is appearing in the top-level Table of Contents, when it's really meant to be a part of the "TypedDict" chapter.
Copy file name to clipboardExpand all lines: docs/spec/typeddict.rst
+7-7Lines changed: 7 additions & 7 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -645,14 +645,14 @@ annotations, which may always want ``Annotated[]`` as the outermost annotation
645
645
646
646
647
647
Read-only Items
648
-
===============
648
+
---------------
649
649
650
650
(Originally specified in :pep:`705`.)
651
651
652
652
.. _`readonly`:
653
653
654
654
``typing.ReadOnly`` type qualifier
655
-
----------------------------------
655
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
656
656
657
657
The ``typing.ReadOnly`` :term:`type qualifier` is used to indicate that an item declared in a ``TypedDict`` definition may not be mutated (added, modified, or removed)::
658
658
@@ -669,7 +669,7 @@ The ``typing.ReadOnly`` :term:`type qualifier` is used to indicate that an item
669
669
670
670
671
671
Interaction with other special types
672
-
------------------------------------
672
+
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
673
673
674
674
``ReadOnly[]`` can be used with ``Required[]``, ``NotRequired[]`` and ``Annotated[]``, in any nesting order:
675
675
@@ -687,7 +687,7 @@ Interaction with other special types
687
687
688
688
689
689
Inheritance
690
-
-----------
690
+
^^^^^^^^^^^
691
691
692
692
Subclasses can redeclare read-only items as non-read-only, allowing them to be mutated::
693
693
@@ -740,7 +740,7 @@ Subclasses can combine these rules::
740
740
Note that these are just consequences of structural typing, but they are highlighted here as the behavior now differs from the rules specified in :pep:`589`.
741
741
742
742
Type consistency
743
-
----------------
743
+
^^^^^^^^^^^^^^^^
744
744
745
745
*This section updates the type consistency rules described above that were created prior to the introduction of ReadOnly*
746
746
@@ -783,7 +783,7 @@ Discussion:
783
783
b: B = a # Accepted by type checker
784
784
785
785
Update method
786
-
-------------
786
+
^^^^^^^^^^^^^
787
787
788
788
In addition to existing type checking rules, type checkers should error if a TypedDict with a read-only item is updated with another TypedDict that declares that key::
789
789
@@ -807,7 +807,7 @@ Unless the declared value is of bottom type (:data:`~typing.Never`)::
807
807
Note: Nothing will ever match the ``Never`` type, so an item annotated with it must be absent.
808
808
809
809
Keyword argument typing
810
-
-----------------------
810
+
^^^^^^^^^^^^^^^^^^^^^^^
811
811
812
812
As discussed in the section :ref:`unpack-kwargs`, an unpacked ``TypedDict`` can be used to annotate ``**kwargs``. Marking one or more of the items of a ``TypedDict`` used in this way as read-only will have no effect on the type signature of the method. However, it *will* prevent the item from being modified in the body of the function::
0 commit comments