Skip to content
Merged
Changes from 3 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
16 changes: 15 additions & 1 deletion docs/source/kinds_of_types.rst
Original file line number Diff line number Diff line change
Expand Up @@ -362,7 +362,6 @@ is needed:

.. code-block:: python


class Container:
items: list[str] # No initializer

Expand Down Expand Up @@ -522,6 +521,21 @@ assigning the type to a variable:
another type -- it's equivalent to the target type except for
:ref:`generic aliases <generic-type-aliases>`.

Since Mypy 0.930 you can also use explicit type aliases which are defined by :pep:`613`.

Implicit type alias declaration rules create confusion when type aliases involve forward references,
invalid types, or violate other restrictions enforced on type alias declaration.
Because the distinction between an unannotated value and a type alias is implicit,
ambiguous or incorrect type alias declarations implicitly default to a valid value assignment.

.. code-block:: python

from typing import TypeAlias # or `from typing_extensions` before `python3.10`

AliasType: TypeAlias = Union[list[dict[tuple[int, str], set[int]]], tuple[str, list[str]]]

Explicit type aliases are unambiguous and improve readability.

.. _named-tuples:

Named tuples
Expand Down