From 07cddeaf72586bf36fb23b57df7c05fa4c2a53de Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 13 May 2023 22:01:26 -0700 Subject: [PATCH 1/2] Minor improvements to typing docs Will comment on the PR with specific motivations. --- Doc/library/typing.rst | 10 ++++++---- 1 file changed, 6 insertions(+), 4 deletions(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index fb1c916b141a25..be0831588e158d 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -19,7 +19,7 @@ This module provides runtime support for type hints. The most fundamental support consists of the types :data:`Any`, :data:`Union`, :data:`Callable`, -:class:`TypeVar`, and :class:`Generic`. For a full specification, please see +:class:`TypeVar`, and :class:`Generic`. For a specification, please see :pep:`484`. For a simplified introduction to type hints, see :pep:`483`. @@ -592,7 +592,7 @@ The module defines the following classes, functions and decorators. when the checked program targets Python 3.9 or newer. The deprecated types will be removed from the :mod:`typing` module - in the first Python version released 5 years after the release of Python 3.9.0. + no sooner than the first Python version released 5 years after the release of Python 3.9.0. See details in :pep:`585`—*Type Hinting Generics In Standard Collections*. @@ -1291,6 +1291,8 @@ These are not used in annotations. They are building blocks for creating generic U = TypeVar('U', bound=str|bytes) # Can be any subtype of the union str|bytes V = TypeVar('V', bound=SupportsAbs) # Can be anything with an __abs__ method +.. _typing-constrained-typevar: + Using a *constrained* type variable, however, means that the ``TypeVar`` can only ever be solved as being exactly one of the constraints given:: @@ -1550,7 +1552,7 @@ These are not used in annotations. They are building blocks for creating generic .. data:: AnyStr - ``AnyStr`` is a :class:`constrained type variable ` defined as + ``AnyStr`` is a :ref:`constrained type variable <_typing-constrained-typevar>` defined as ``AnyStr = TypeVar('AnyStr', str, bytes)``. It is meant to be used for functions that may accept any kind of string @@ -2112,7 +2114,7 @@ Other concrete types Python 2 is no longer supported, and most type checkers also no longer support type checking Python 2 code. Removal of the alias is not currently planned, but users are encouraged to use - :class:`str` instead of ``Text`` wherever possible. + :class:`str` instead of ``Text``. Abstract Base Classes --------------------- From 68c7e8b31d24d2dab751dbc5454b11c3e71453b5 Mon Sep 17 00:00:00 2001 From: Jelle Zijlstra Date: Sat, 13 May 2023 22:06:11 -0700 Subject: [PATCH 2/2] fix label --- Doc/library/typing.rst | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Doc/library/typing.rst b/Doc/library/typing.rst index be0831588e158d..c300c4257f0e81 100644 --- a/Doc/library/typing.rst +++ b/Doc/library/typing.rst @@ -1552,7 +1552,7 @@ These are not used in annotations. They are building blocks for creating generic .. data:: AnyStr - ``AnyStr`` is a :ref:`constrained type variable <_typing-constrained-typevar>` defined as + ``AnyStr`` is a :ref:`constrained type variable ` defined as ``AnyStr = TypeVar('AnyStr', str, bytes)``. It is meant to be used for functions that may accept any kind of string