From 7bd5b3d2d99c2709fab5d0bf9fce112f5f132cbf Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 28 Oct 2021 21:30:27 +0100 Subject: [PATCH 1/2] [3.9] bpo-45655: Add "relevant PEPs" section to ``typing`` documentation Backport of https://github.com/python/cpython/pull/29280 to the 3.9 branch. --- Doc/library/typing.rst | 38 ++++++++++++++++--- .../2021-10-28-21-28-07.bpo-45655.aPYGaS.rst | 2 + 2 files changed, 34 insertions(+), 6 deletions(-) create mode 100644 Misc/NEWS.d/next/Documentation/2021-10-28-21-28-07.bpo-45655.aPYGaS.rst diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 78ab760d86a547..86bf8261411148 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -17,12 +17,11 @@ -------------- -This module provides runtime support for type hints as specified by -:pep:`484`, :pep:`526`, :pep:`544`, :pep:`586`, :pep:`589`, and :pep:`591`. -The most fundamental support consists of the types :data:`Any`, :data:`Union`, -:data:`Tuple`, :data:`Callable`, :class:`TypeVar`, and -:class:`Generic`. For full specification please see :pep:`484`. For -a simplified introduction to type hints see :pep:`483`. +This module provides runtime support for type hints. The most fundamental +support consists of the types :data:`Any`, :data:`Union`, :data:`Tuple`, +:data:`Callable`, :class:`TypeVar`, and :class:`Generic`. For a full +specification, please see :pep:`484`. For a simplified introduction to type +hints, see :pep:`483`. The function below takes and returns a string and is annotated as follows:: @@ -34,6 +33,33 @@ In the function ``greeting``, the argument ``name`` is expected to be of type :class:`str` and the return type :class:`str`. Subtypes are accepted as arguments. +.. _relevant-peps: + +Relevant PEPs +============= + +Since the initial introduction of type hints in :pep:`484` and :pep:`483`, a +number of PEPs have modified and enhanced Python's framework for type +annotations. These include: + +* :pep:`526`: Syntax for Variable Annotations + *Introducing* syntax for annotating variables outside of function + definitions, and :data:`ClassVar` +* :pep:`544`: Protocols: Structural subtyping (static duck typing) + *Introducing* :class:`Protocol` and the + :func:`@runtime_checkable` decorator +* :pep:`585`: Type Hinting Generics In Standard Collections + *Introducing* the ability to use builtin collections and ABCs as + :term:`generic types` +* :pep:`586`: Literal Types + *Introducing* :data:`Literal` +* :pep:`589`: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys + *Introducing* :class:`TypedDict` +* :pep:`591`: Adding a final qualifier to typing + *Introducing* :data:`Final` and the :func:`@final` decorator +* :pep:`593`: Flexible function and variable annotations + *Introducing* :data:`Annotated` + Type aliases ============ diff --git a/Misc/NEWS.d/next/Documentation/2021-10-28-21-28-07.bpo-45655.aPYGaS.rst b/Misc/NEWS.d/next/Documentation/2021-10-28-21-28-07.bpo-45655.aPYGaS.rst new file mode 100644 index 00000000000000..fc5b3d07888175 --- /dev/null +++ b/Misc/NEWS.d/next/Documentation/2021-10-28-21-28-07.bpo-45655.aPYGaS.rst @@ -0,0 +1,2 @@ +Add a new "relevant PEPs" section to the top of the documentation for the +``typing`` module. Patch by Alex Waygood. From cfb40d44410a638dda0a26972d542856b6a97d4b Mon Sep 17 00:00:00 2001 From: Alex Waygood Date: Thu, 28 Oct 2021 21:36:06 +0100 Subject: [PATCH 2/2] Things that are now data were then classes --- Doc/library/typing.rst | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index 86bf8261411148..295f2ae8905af1 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -52,13 +52,13 @@ annotations. These include: *Introducing* the ability to use builtin collections and ABCs as :term:`generic types` * :pep:`586`: Literal Types - *Introducing* :data:`Literal` + *Introducing* :class:`Literal` * :pep:`589`: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys *Introducing* :class:`TypedDict` * :pep:`591`: Adding a final qualifier to typing *Introducing* :data:`Final` and the :func:`@final` decorator * :pep:`593`: Flexible function and variable annotations - *Introducing* :data:`Annotated` + *Introducing* :class:`Annotated` Type aliases ============