Skip to content
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

Fixed the header levels in the "Read-only Items". #1727

Merged
merged 1 commit into from
Apr 24, 2024
Merged
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
14 changes: 7 additions & 7 deletions docs/spec/typeddict.rst
Original file line number Diff line number Diff line change
Expand Up @@ -645,14 +645,14 @@ annotations, which may always want ``Annotated[]`` as the outermost annotation


Read-only Items
===============
---------------

(Originally specified in :pep:`705`.)

.. _`readonly`:

``typing.ReadOnly`` type qualifier
----------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

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)::

Expand All @@ -669,7 +669,7 @@ The ``typing.ReadOnly`` :term:`type qualifier` is used to indicate that an item


Interaction with other special types
------------------------------------
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

``ReadOnly[]`` can be used with ``Required[]``, ``NotRequired[]`` and ``Annotated[]``, in any nesting order:

Expand All @@ -687,7 +687,7 @@ Interaction with other special types


Inheritance
-----------
^^^^^^^^^^^

Subclasses can redeclare read-only items as non-read-only, allowing them to be mutated::

Expand Down Expand Up @@ -740,7 +740,7 @@ Subclasses can combine these rules::
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`.

Type consistency
----------------
^^^^^^^^^^^^^^^^

*This section updates the type consistency rules described above that were created prior to the introduction of ReadOnly*

Expand Down Expand Up @@ -783,7 +783,7 @@ Discussion:
b: B = a # Accepted by type checker

Update method
-------------
^^^^^^^^^^^^^

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::

Expand All @@ -807,7 +807,7 @@ Unless the declared value is of bottom type (:data:`~typing.Never`)::
Note: Nothing will ever match the ``Never`` type, so an item annotated with it must be absent.

Keyword argument typing
-----------------------
^^^^^^^^^^^^^^^^^^^^^^^

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::

Expand Down