Skip to content

Commit a44d415

Browse files
authored
Docs: use role to link to PEPs (#1568)
1 parent ebedabf commit a44d415

File tree

3 files changed

+59
-83
lines changed

3 files changed

+59
-83
lines changed

docs/index.rst

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -102,33 +102,33 @@ Typing PEPs
102102

103103
https://peps.python.org/topic/typing
104104

105-
* `PEP 482 <https://www.python.org/dev/peps/pep-0482/>`_, literature overview on type hints
106-
* `PEP 483 <https://www.python.org/dev/peps/pep-0483/>`_, background on type hints
107-
* `PEP 484 <https://www.python.org/dev/peps/pep-0484/>`_, type hints
108-
* `PEP 526 <https://www.python.org/dev/peps/pep-0526/>`_, variable annotations and ``ClassVar``
109-
* `PEP 544 <https://www.python.org/dev/peps/pep-0544/>`_, ``Protocol``
110-
* `PEP 561 <https://www.python.org/dev/peps/pep-0561/>`_, distributing typed packages
111-
* `PEP 563 <https://www.python.org/dev/peps/pep-0563/>`_, ``from __future__ import annotations``
112-
* `PEP 585 <https://www.python.org/dev/peps/pep-0585/>`_, subscriptable generics in the standard library
113-
* `PEP 586 <https://www.python.org/dev/peps/pep-0586/>`_, ``Literal``
114-
* `PEP 589 <https://www.python.org/dev/peps/pep-0589/>`_, ``TypedDict``
115-
* `PEP 591 <https://www.python.org/dev/peps/pep-0591/>`_, ``Final``
116-
* `PEP 593 <https://www.python.org/dev/peps/pep-0593/>`_, ``Annotated``
117-
* `PEP 604 <https://www.python.org/dev/peps/pep-0604/>`_, union syntax with ``|``
118-
* `PEP 612 <https://www.python.org/dev/peps/pep-0612/>`_, ``ParamSpec``
119-
* `PEP 613 <https://www.python.org/dev/peps/pep-0613/>`_, ``TypeAlias``
120-
* `PEP 646 <https://www.python.org/dev/peps/pep-0646/>`_, variadic generics and ``TypeVarTuple``
121-
* `PEP 647 <https://www.python.org/dev/peps/pep-0647/>`_, ``TypeGuard``
122-
* `PEP 649 <https://www.python.org/dev/peps/pep-0649/>`_ (draft), ``from __future__ import co_annotations``
123-
* `PEP 655 <https://www.python.org/dev/peps/pep-0655/>`_, ``Required`` and ``NotRequired``
124-
* `PEP 673 <https://www.python.org/dev/peps/pep-0673/>`_, ``Self``
125-
* `PEP 675 <https://www.python.org/dev/peps/pep-0675/>`_, ``LiteralString``
126-
* `PEP 677 <https://www.python.org/dev/peps/pep-0677/>`_ (rejected), ``(int, str) -> bool`` callable type syntax
127-
* `PEP 681 <https://www.python.org/dev/peps/pep-0681/>`_ ``@dataclass_transform()``
128-
* `PEP 688 <https://www.python.org/dev/peps/pep-0688/>`_ ``Buffer``
129-
* `PEP 692 <https://www.python.org/dev/peps/pep-0692/>`_ ``Unpack[TypedDict]`` for ``**kwargs``
130-
* `PEP 695 <https://www.python.org/dev/peps/pep-0695/>`_ ``class Class[T]:`` type parameter syntax
131-
* `PEP 696 <https://www.python.org/dev/peps/pep-0696/>`_ (draft), defaults for type variables
132-
* `PEP 698 <https://www.python.org/dev/peps/pep-0698/>`_ ``@override``
133-
* `PEP 702 <https://www.python.org/dev/peps/pep-0702/>`_ (draft), ``@deprecated()``
134-
* `PEP 705 <https://www.python.org/dev/peps/pep-0705/>`_ (draft), ``TypedMapping``
105+
* :pep:`482`, literature overview on type hints
106+
* :pep:`483`, background on type hints
107+
* :pep:`484`, type hints
108+
* :pep:`526`, variable annotations and ``ClassVar``
109+
* :pep:`544`, ``Protocol``
110+
* :pep:`561`, distributing typed packages
111+
* :pep:`563`, ``from __future__ import annotations``
112+
* :pep:`585`, subscriptable generics in the standard library
113+
* :pep:`586`, ``Literal``
114+
* :pep:`589`, ``TypedDict``
115+
* :pep:`591`, ``Final``
116+
* :pep:`593`, ``Annotated``
117+
* :pep:`604`, union syntax with ``|``
118+
* :pep:`612`, ``ParamSpec``
119+
* :pep:`613`, ``TypeAlias``
120+
* :pep:`646`, variadic generics and ``TypeVarTuple``
121+
* :pep:`647`, ``TypeGuard``
122+
* :pep:`649` (draft), ``from __future__ import co_annotations``
123+
* :pep:`655`, ``Required`` and ``NotRequired``
124+
* :pep:`673`, ``Self``
125+
* :pep:`675`, ``LiteralString``
126+
* :pep:`677` (rejected), ``(int, str) -> bool`` callable type syntax
127+
* :pep:`681` ``@dataclass_transform()``
128+
* :pep:`688` ``Buffer``
129+
* :pep:`692` ``Unpack[TypedDict]`` for ``**kwargs``
130+
* :pep:`695` ``class Class[T]:`` type parameter syntax
131+
* :pep:`696` (draft), defaults for type variables
132+
* :pep:`698` ``@override``
133+
* :pep:`702` (draft), ``@deprecated()``
134+
* :pep:`705` (draft), ``TypedMapping``

docs/source/libraries.rst

Lines changed: 12 additions & 19 deletions
Original file line numberDiff line numberDiff line change
@@ -482,8 +482,7 @@ the original signature of the decorated function.
482482
483483
Decorators that mutate the signature of the decorated function present
484484
challenges for type annotations. The ``ParamSpec`` and ``Concatenate``
485-
mechanisms described in `PEP
486-
612 <https://www.python.org/dev/peps/pep-0612/>`__ provide some help
485+
mechanisms described in :pep:`612` provide some help
487486
here, but these are available only in Python 3.10 and newer. More
488487
complex signature mutations may require type annotations that erase the
489488
original signature, thus blinding type checkers and other tools that
@@ -495,7 +494,7 @@ Generic Classes and Functions
495494

496495
Classes and functions that can operate in a generic manner on various
497496
types should declare themselves as generic using the mechanisms
498-
described in `PEP 484 <https://www.python.org/dev/peps/pep-0484/>`__.
497+
described in :pep:`484`.
499498
This includes the use of ``TypeVar`` symbols. Typically, a ``TypeVar``
500499
should be private to the file that declares it, and should therefore
501500
begin with an underscore.
@@ -507,7 +506,7 @@ Type aliases are symbols that refer to other types. Generic type aliases
507506
(those that refer to unspecialized generic classes) are supported by
508507
most type checkers.
509508

510-
`PEP 613 <https://www.python.org/dev/peps/pep-0613/>`__ provides a way
509+
:pep:`613` provides a way
511510
to explicitly designate a symbol as a type alias using the new TypeAlias
512511
annotation.
513512

@@ -556,25 +555,23 @@ Final Classes and Methods
556555
-------------------------
557556

558557
Classes that are not intended to be subclassed should be decorated as
559-
``@final`` as described in `PEP
560-
591 <https://www.python.org/dev/peps/pep-0591/>`__. The same decorator
558+
``@final`` as described in :pep:`591`. The same decorator
561559
can also be used to specify methods that cannot be overridden by
562560
subclasses.
563561

564562
Literals
565563
--------
566564

567565
Type annotations should make use of the Literal type where appropriate,
568-
as described in `PEP 586 <https://www.python.org/dev/peps/pep-0586/>`__.
566+
as described in :pep:`586`.
569567
Literals allow for more type specificity than their non-literal
570568
counterparts.
571569

572570
Constants
573571
---------
574572

575573
Constant values (those that are read-only) can be specified using the
576-
Final annotation as described in `PEP
577-
591 <https://www.python.org/dev/peps/pep-0591/>`__.
574+
Final annotation as described in :pep:`591`.
578575

579576
Type checkers will also typically treat variables that are named using
580577
all upper-case characters as constants.
@@ -606,16 +603,13 @@ Typed Dictionaries, Data Classes, and Named Tuples
606603
If your library runs only on newer versions of Python, you are
607604
encouraged to use some of the new type-friendly classes.
608605

609-
NamedTuple (described in `PEP
610-
484 <https://www.python.org/dev/peps/pep-0484/>`__) is preferred over
606+
NamedTuple (described in :pep:`484`) is preferred over
611607
namedtuple.
612608

613-
Data classes (described in `PEP
614-
557 <https://www.python.org/dev/peps/pep-0557/>`__) is preferred over
609+
Data classes (described in :pep:`557`) is preferred over
615610
untyped dictionaries.
616611

617-
TypedDict (described in `PEP
618-
589 <https://www.python.org/dev/peps/pep-0589/>`__) is preferred over
612+
TypedDict (described in :pep:`589`) is preferred over
619613
untyped dictionaries.
620614

621615
Compatibility with Older Python Versions
@@ -646,9 +640,9 @@ Type Comment Annotations
646640
------------------------
647641

648642
Python 3.0 introduced syntax for parameter and return type annotations,
649-
as specified in `PEP 484 <https://www.python.org/dev/peps/pep-0484/>`__.
643+
as specified in :pep:`484`.
650644
Python 3.6 introduced support for variable type annotations, as
651-
specified in `PEP 526 <https://www.python.org/dev/peps/pep-0526/>`__.
645+
specified in :pep:`526`.
652646

653647
If you need to support older versions of Python, type annotations can
654648
still be provided as “type comments”. These comments take the form #
@@ -710,8 +704,7 @@ Docstrings
710704
==========
711705

712706
Docstrings should be provided for all classes, functions, and methods in
713-
the interface. They should be formatted according to `PEP
714-
257 <https://www.python.org/dev/peps/pep-0257/>`__.
707+
the interface. They should be formatted according to :pep:`257`.
715708

716709
There is currently no single agreed-upon standard for function and
717710
method docstrings, but several common variants have emerged. We

docs/source/stubs.rst

Lines changed: 17 additions & 34 deletions
Original file line numberDiff line numberDiff line change
@@ -52,10 +52,10 @@ Type checker authors are encouraged to support syntax features from
5252
post-3.7 Python versions, although type stub authors should not use such
5353
features if they wish to maintain compatibility with all type checkers.
5454

55-
For example, Python 3.7 added the ``async`` keyword (see PEP 492 [#pep492]_).
55+
For example, Python 3.7 added the ``async`` keyword (see :pep:`492`).
5656
Stub authors should use it to mark coroutines, even if the implementation
5757
still uses the ``@coroutine`` decorator. On the other hand, type stubs should
58-
not use the positional-only syntax from PEP 570 [#pep570]_, introduced in
58+
not use the positional-only syntax from :pep:`570`, introduced in
5959
Python 3.8, although type checker authors are encouraged to support it.
6060

6161
Stubs are treated as if ``from __future__ import annotations`` is enabled.
@@ -72,7 +72,7 @@ Distribution
7272
============
7373

7474
Type stubs can be distributed with or separately from the implementation;
75-
see PEP 561 [#pep561]_ for more information. The
75+
see :pep:`561` for more information. The
7676
`typeshed <https://github.com/python/typeshed>`_ project
7777
includes stubs for Python's standard library and several third-party
7878
packages. The stubs for the standard library are usually distributed with type checkers and do not
@@ -112,7 +112,7 @@ Standard Python comments are accepted everywhere Python syntax allows them.
112112
Two kinds of structured comments are accepted:
113113

114114
* A ``# type: X`` comment at the end of a line that defines a variable,
115-
declaring that the variable has type ``X``. However, PEP 526-style [#pep526]_
115+
declaring that the variable has type ``X``. However, :pep:`526`-style
116116
variable annotations are preferred over type comments.
117117
* A ``# type: ignore`` comment at the end of any line, which suppresses all type
118118
errors in that line. The type checker mypy supports suppressing certain
@@ -124,7 +124,7 @@ Imports
124124

125125
Type stubs distinguish between imports that are re-exported and those
126126
that are only used internally. Imports are re-exported if they use one of these
127-
forms:[#pep484]_
127+
forms (:pep:`484`):
128128

129129
* ``import X as X``
130130
* ``from Y import X as X``
@@ -175,7 +175,7 @@ Type checkers support cyclic imports in stub files.
175175
Built-in Generics
176176
-----------------
177177

178-
PEP 585 [#pep585]_ built-in generics are supported and should be used instead
178+
:pep:`585` built-in generics are supported and should be used instead
179179
of the corresponding types from ``typing``::
180180

181181
from collections import defaultdict
@@ -268,17 +268,17 @@ Functions and Methods
268268

269269
Function and method definition syntax follows general Python syntax.
270270
Unless an argument name is prefixed with two underscores (but not suffixed
271-
with two underscores), it can be used as a keyword argument [#pep484]_::
271+
with two underscores), it can be used as a keyword argument (:pep:`484`)::
272272

273273
# x is positional-only
274274
# y can be used positionally or as keyword argument
275275
# z is keyword-only
276276
def foo(__x, y, *, z): ...
277277

278-
PEP 570 [#pep570]_ style positional-only parameters are currently not
278+
:pep:`570` style positional-only parameters are currently not
279279
supported.
280280

281-
If an argument or return type is unannotated, per PEP 484 [#pep484]_ its
281+
If an argument or return type is unannotated, per :pep:`484` its
282282
type is assumed to be ``Any``. It is preferred to leave unknown
283283
types unannotated rather than explicitly marking them as ``Any``, as some
284284
type checkers can optionally warn about unannotated arguments.
@@ -314,7 +314,7 @@ But::
314314
@classmethod
315315
def create_it(cls: _T) -> _T: ... # cls has type _T
316316

317-
PEP 612 [#pep612]_ parameter specification variables (``ParamSpec``)
317+
:pep:`612` parameter specification variables (``ParamSpec``)
318318
are supported in argument and return types::
319319

320320
_P = ParamSpec("_P")
@@ -325,7 +325,7 @@ are supported in argument and return types::
325325
However, ``Concatenate`` from PEP 612 is not yet supported; nor is using
326326
a ``ParamSpec`` to parameterize a generic class.
327327

328-
PEP 647 [#pep647]_ type guards are supported.
328+
:pep:`647` type guards are supported.
329329

330330
Using a function or method body other than the ellipsis literal is currently
331331
unspecified. Stub authors may experiment with other bodies, but it is up to
@@ -355,7 +355,7 @@ Aliases and NewType
355355
-------------------
356356

357357
Type checkers should accept module-level type aliases, optionally using
358-
``TypeAlias`` (PEP 613 [#pep613]_), e.g.::
358+
``TypeAlias`` (:pep:`613`), e.g.::
359359

360360
_IntList = list[int]
361361
_StrList: TypeAlias = list[str]
@@ -370,7 +370,7 @@ e.g.::
370370
def f(self) -> int: ...
371371
g = f
372372

373-
A type alias may contain type variables. As per PEP 484 [#pep484]_,
373+
A type alias may contain type variables. As per :pep:`484`,
374374
all type variables must be substituted when the alias is used::
375375

376376
_K = TypeVar("_K")
@@ -521,7 +521,7 @@ Unsupported Features
521521
Currently, the following features are not supported by all type checkers
522522
and should not be used in stubs:
523523

524-
* Positional-only argument syntax (PEP 570 [#pep570]_). Instead, use
524+
* Positional-only argument syntax (:pep:`570`). Instead, use
525525
the syntax described in the section :ref:`supported-functions`.
526526
[#ts-4972]_
527527

@@ -607,7 +607,7 @@ Structural Types
607607

608608
As seen in the example with ``_Readable`` in the previous section, a common use
609609
of stub-only objects is to model types that are best described by their
610-
structure. These objects are called protocols [#pep544]_, and it is encouraged
610+
structure. These objects are called protocols (:pep:`544`), and it is encouraged
611611
to use them freely to describe simple structural types.
612612

613613
It is `recommended <#private-definitions>`_ to prefix stubs-only object names with ``_``.
@@ -765,8 +765,8 @@ who wish to provide a consistent style for type stubs. Type checkers
765765
should not reject stubs that do not follow these recommendations, but
766766
linters can warn about them.
767767

768-
Stub files should generally follow the Style Guide for Python Code (PEP 8)
769-
[#pep8]_ and the :ref:`best-practices`. There are a few exceptions, outlined below, that take the
768+
Stub files should generally follow the Style Guide for Python Code (:pep:`8`)
769+
and the :ref:`best-practices`. There are a few exceptions, outlined below, that take the
770770
different structure of stub files into account and are aimed to create
771771
more concise files.
772772

@@ -989,23 +989,6 @@ No::
989989
References
990990
==========
991991

992-
PEPs
993-
----
994-
995-
.. [#pep8] PEP 8 -- Style Guide for Python Code, van Rossum et al. (https://www.python.org/dev/peps/pep-0008/)
996-
.. [#pep484] PEP 484 -- Type Hints, van Rossum et al. (https://www.python.org/dev/peps/pep-0484)
997-
.. [#pep492] PEP 492 -- Coroutines with async and await syntax, Selivanov (https://www.python.org/dev/peps/pep-0492/)
998-
.. [#pep526] PEP 526 -- Syntax for Variable Annotations, Gonzalez et al. (https://www.python.org/dev/peps/pep-0526)
999-
.. [#pep544] PEP 544 -- Protocols: Structural Subtyping, Levkivskyi et al. (https://www.python.org/dev/peps/pep-0544)
1000-
.. [#pep561] PEP 561 -- Distributing and Packaging Type Information, Smith (https://www.python.org/dev/peps/pep-0561)
1001-
.. [#pep570] PEP 570 -- Python Positional-Only Parameters, Hastings et al. (https://www.python.org/dev/peps/pep-0570)
1002-
.. [#pep585] PEP 585 -- Type Hinting Generics In Standard Collections, Langa (https://www.python.org/dev/peps/pep-0585)
1003-
.. [#pep604] PEP 604 -- Allow writing union types as X | Y, Prados and Moss (https://www.python.org/dev/peps/pep-0604)
1004-
.. [#pep612] PEP 612 -- Parameter Specification Variables, Mendoza (https://www.python.org/dev/peps/pep-0612)
1005-
.. [#pep613] PEP 613 -- Explicit Type Aliases, Zhu (https://www.python.org/dev/peps/pep-0613)
1006-
.. [#pep647] PEP 647 -- User-Defined Type Guards, Traut (https://www.python.org/dev/peps/pep-0647)
1007-
.. [#pep3107] PEP 3107 -- Function Annotations, Winter and Lownds (https://www.python.org/dev/peps/pep-3107)
1008-
1009992
Bugs
1010993
----
1011994

0 commit comments

Comments
 (0)