Skip to content

Commit 2c8a002

Browse files
AlexWaygoodambv
andauthored
[3.10] bo-45655: Add "relevant PEPs" section to typing documentation (GH-29302)
The list of PEPs at the top of the documentation for the ``typing`` module has become too long to be readable. This PR proposes presenting this information in a more structured and readable way by adding a new "relevant PEPs" section to the ``typing`` docs. (cherry picked from commit 03db1bb) Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Łukasz Langa <[email protected]>
1 parent 6b86702 commit 2c8a002

File tree

3 files changed

+47
-11
lines changed

3 files changed

+47
-11
lines changed

Doc/library/typing.rst

Lines changed: 41 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -17,13 +17,11 @@
1717

1818
--------------
1919

20-
This module provides runtime support for type hints as specified by
21-
:pep:`484`, :pep:`526`, :pep:`544`, :pep:`586`, :pep:`589`, :pep:`591`,
22-
:pep:`593`, :pep:`612`, :pep:`613` and :pep:`647`.
23-
The most fundamental support consists of the types :data:`Any`, :data:`Union`,
24-
:data:`Tuple`, :data:`Callable`, :class:`TypeVar`, and
25-
:class:`Generic`. For full specification please see :pep:`484`. For
26-
a simplified introduction to type hints see :pep:`483`.
20+
This module provides runtime support for type hints. The most fundamental
21+
support consists of the types :data:`Any`, :data:`Union`, :data:`Tuple`,
22+
:data:`Callable`, :class:`TypeVar`, and :class:`Generic`. For a full
23+
specification, please see :pep:`484`. For a simplified introduction to type
24+
hints, see :pep:`483`.
2725

2826

2927
The function below takes and returns a string and is annotated as follows::
@@ -35,6 +33,42 @@ In the function ``greeting``, the argument ``name`` is expected to be of type
3533
:class:`str` and the return type :class:`str`. Subtypes are accepted as
3634
arguments.
3735

36+
.. _relevant-peps:
37+
38+
Relevant PEPs
39+
=============
40+
41+
Since the initial introduction of type hints in :pep:`484` and :pep:`483`, a
42+
number of PEPs have modified and enhanced Python's framework for type
43+
annotations. These include:
44+
45+
* :pep:`526`: Syntax for Variable Annotations
46+
*Introducing* syntax for annotating variables outside of function
47+
definitions, and :data:`ClassVar`
48+
* :pep:`544`: Protocols: Structural subtyping (static duck typing)
49+
*Introducing* :class:`Protocol` and the
50+
:func:`@runtime_checkable<runtime_checkable>` decorator
51+
* :pep:`585`: Type Hinting Generics In Standard Collections
52+
*Introducing* the ability to use builtin collections and ABCs as
53+
:term:`generic types<generic type>`
54+
* :pep:`586`: Literal Types
55+
*Introducing* :data:`Literal`
56+
* :pep:`589`: TypedDict: Type Hints for Dictionaries with a Fixed Set of Keys
57+
*Introducing* :class:`TypedDict`
58+
* :pep:`591`: Adding a final qualifier to typing
59+
*Introducing* :data:`Final` and the :func:`@final<final>` decorator
60+
* :pep:`593`: Flexible function and variable annotations
61+
*Introducing* :data:`Annotated`
62+
* :pep:`604`: Allow writing union types as ``X | Y``
63+
*Introducing* :data:`types.UnionType` and the ability to use
64+
the binary-or operator ``|`` as syntactic sugar for a union of types
65+
* :pep:`612`: Parameter Specification Variables
66+
*Introducing* :class:`ParamSpec` and :data:`Concatenate`
67+
* :pep:`613`: Explicit Type Aliases
68+
*Introducing* :data:`TypeAlias`
69+
* :pep:`647`: User-Defined Type Guards
70+
*Introducing* :data:`TypeGuard`
71+
3872
.. _type-aliases:
3973

4074
Type aliases

Doc/tools/susp-ignored.csv

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -376,7 +376,7 @@ library/importlib.metadata,,:main,"EntryPoint(name='wheel', value='wheel.cli:mai
376376
library/importlib.metadata,,`,loading the metadata for packages for the indicated ``context``.
377377
library/re,,`,"`"
378378
using/configure,84,:db2,=db1:db2:...
379-
library/typing,1011,`,# Type of ``val`` is narrowed to ``str``
380-
library/typing,1011,`,"# Else, type of ``val`` is narrowed to ``float``."
381-
library/typing,1011,`,# Type of ``val`` is narrowed to ``List[str]``.
382-
library/typing,1011,`,# Type of ``val`` remains as ``List[object]``.
379+
library/typing,,`,# Type of ``val`` is narrowed to ``str``
380+
library/typing,,`,"# Else, type of ``val`` is narrowed to ``float``."
381+
library/typing,,`,# Type of ``val`` is narrowed to ``List[str]``.
382+
library/typing,,`,# Type of ``val`` remains as ``List[object]``.
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Add a new "relevant PEPs" section to the top of the documentation for the
2+
``typing`` module. Patch by Alex Waygood.

0 commit comments

Comments
 (0)