Skip to content

Commit 47dab6a

Browse files
hoeflingGuido van Rossum
authored andcommitted
Replace hardcoded links with intersphinx refs in docs (#7623)
Configured intersphinx extension, replaced external links with intersphinx refs and pep role. Signed-off-by: Oleg Höfling <[email protected]>
1 parent 47093eb commit 47dab6a

23 files changed

+96
-109
lines changed

docs/source/additional_features.rst

Lines changed: 7 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -9,9 +9,10 @@ of the previous sections.
99
Dataclasses
1010
***********
1111

12-
In Python 3.7, a new ``dataclasses`` module has been added to the standard library.
12+
In Python 3.7, a new :py:mod:`dataclasses` module has been added to the standard library.
1313
This module allows defining and customizing simple boilerplate-free classes.
14-
They can be defined using the ``@dataclasses.dataclass`` decorator:
14+
They can be defined using the :py:func:`@dataclasses.dataclass
15+
<python:dataclasses.dataclass>` decorator:
1516

1617
.. code-block:: python
1718
@@ -65,8 +66,8 @@ class can be used:
6566
6667
val = unbox(BoxedData(42, "<important>")) # OK, inferred type is int
6768
68-
For more information see `official docs <https://docs.python.org/3/library/dataclasses.html>`_
69-
and `PEP 557 <https://www.python.org/dev/peps/pep-0557/>`_.
69+
For more information see :doc:`official docs <python:library/dataclasses>`
70+
and :pep:`557`.
7071

7172
Caveats/Known Issues
7273
====================
@@ -110,7 +111,7 @@ do **not** work:
110111
The attrs package
111112
*****************
112113

113-
`attrs <http://www.attrs.org/en/stable>`_ is a package that lets you define
114+
:doc:`attrs <attrs:index>` is a package that lets you define
114115
classes without writing boilerplate code. Mypy can detect uses of the
115116
package and will generate the necessary method definitions for decorated
116117
classes using the type annotations it finds.
@@ -176,7 +177,7 @@ Caveats/Known Issues
176177
will complain about not understanding the argument and the type annotation in
177178
``__init__`` will be replaced by ``Any``.
178179

179-
* `Validator decorators <http://www.attrs.org/en/stable/examples.html#validators>`_
180+
* :ref:`Validator decorators <attrs:examples_validators>`
180181
and `default decorators <http://www.attrs.org/en/stable/examples.html#defaults>`_
181182
are not type-checked against the attribute they are setting/validating.
182183

docs/source/cheat_sheet.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Type hints cheat sheet (Python 2)
44
=================================
55

6-
This document is a quick cheat sheet showing how the
7-
`PEP 484 <https://www.python.org/dev/peps/pep-0484/>`_ type
6+
This document is a quick cheat sheet showing how the :pep:`484` type
87
language represents various common types in Python 2.
98

109
.. note::

docs/source/cheat_sheet_py3.rst

Lines changed: 3 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -3,8 +3,7 @@
33
Type hints cheat sheet (Python 3)
44
=================================
55

6-
This document is a quick cheat sheet showing how the
7-
`PEP 484 <https://www.python.org/dev/peps/pep-0484/>`_ type
6+
This document is a quick cheat sheet showing how the :pep:`484` type
87
annotation notation represents various common types in Python 3.
98

109
.. note::
@@ -18,9 +17,8 @@ annotation notation represents various common types in Python 3.
1817
Variables
1918
*********
2019

21-
Python 3.6 introduced a syntax for annotating variables in
22-
`PEP 526 <https://www.python.org/dev/peps/pep-0526/>`_ and
23-
we use it in most examples.
20+
Python 3.6 introduced a syntax for annotating variables in :pep:`526`
21+
and we use it in most examples.
2422

2523
.. code-block:: python
2624

docs/source/command_line.rst

Lines changed: 9 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -78,7 +78,7 @@ imports.
7878

7979
``--namespace-packages``
8080
This flag enables import discovery to use namespace packages (see
81-
`PEP 420`_). In particular, this allows discovery of imported
81+
:pep:`420`). In particular, this allows discovery of imported
8282
packages that don't have an ``__init__.py`` (or ``__init__.pyi``)
8383
file.
8484

@@ -127,23 +127,23 @@ imports.
127127
see :ref:`Following imports <follow-imports>`.
128128

129129
``--python-executable EXECUTABLE``
130-
This flag will have mypy collect type information from `PEP 561`_
130+
This flag will have mypy collect type information from :pep:`561`
131131
compliant packages installed for the Python executable ``EXECUTABLE``.
132-
If not provided, mypy will use PEP 561 compliant packages installed for
132+
If not provided, mypy will use :pep:`561` compliant packages installed for
133133
the Python executable running mypy.
134134

135-
See :ref:`installed-packages` for more on making PEP 561 compliant packages.
135+
See :ref:`installed-packages` for more on making :pep:`561` compliant packages.
136136

137137
``--no-site-packages``
138-
This flag will disable searching for `PEP 561`_ compliant packages. This
138+
This flag will disable searching for :pep:`561` compliant packages. This
139139
will also disable searching for a usable Python executable.
140140

141141
Use this flag if mypy cannot find a Python executable for the version of
142-
Python being checked, and you don't need to use PEP 561 typed packages.
142+
Python being checked, and you don't need to use :pep:`561` typed packages.
143143
Otherwise, use ``--python-executable``.
144144

145145
``--no-silence-site-packages``
146-
By default, mypy will suppress any error messages generated within PEP 561
146+
By default, mypy will suppress any error messages generated within :pep:`561`
147147
compliant packages. Adding this flag will disable this behavior.
148148

149149

@@ -165,7 +165,7 @@ For more information on how to use these flags, see :ref:`version_and_platform_c
165165
``--py2`` flags are aliases for ``--python-version 2.7``.
166166

167167
This flag will attempt to find a Python executable of the corresponding
168-
version to search for `PEP 561`_ compliant packages. If you'd like to
168+
version to search for :pep:`561` compliant packages. If you'd like to
169169
disable this, use the ``--no-site-packages`` flag (see
170170
:ref:`import-discovery` for more details).
171171

@@ -178,7 +178,7 @@ For more information on how to use these flags, see :ref:`version_and_platform_c
178178
default to using whatever operating system you are currently using.
179179

180180
The ``PLATFORM`` parameter may be any string supported by
181-
`sys.platform <https://docs.python.org/3/library/sys.html#sys.platform>`_.
181+
:py:data:`sys.platform`.
182182

183183
.. _always-true:
184184

@@ -680,8 +680,4 @@ Miscellaneous
680680
have many scripts that import a large package, the behavior enabled
681681
by this flag is often more convenient.)
682682

683-
.. _PEP 420: https://www.python.org/dev/peps/pep-0420/
684-
685-
.. _PEP 561: https://www.python.org/dev/peps/pep-0561/
686-
687683
.. _lxml: https://pypi.org/project/lxml/

docs/source/common_issues.rst

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -438,8 +438,7 @@ to have Python 2.7 installed to perform this check.
438438

439439
To target a different operating system, use the ``--platform PLATFORM`` flag.
440440
For example, to verify your code typechecks if it were run in Windows, pass
441-
in ``--platform win32``. See the documentation for
442-
`sys.platform <https://docs.python.org/3/library/sys.html#sys.platform>`_
441+
in ``--platform win32``. See the documentation for :py:data:`sys.platform`
443442
for examples of valid platform parameters.
444443

445444
.. _reveal-type:

docs/source/conf.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -30,7 +30,7 @@
3030
# Add any Sphinx extension module names here, as strings. They can be
3131
# extensions coming with Sphinx (named 'sphinx.ext.*') or your custom
3232
# ones.
33-
extensions = []
33+
extensions = ['sphinx.ext.intersphinx']
3434

3535
# Add any paths that contain templates here, relative to this directory.
3636
templates_path = ['_templates']
@@ -266,3 +266,11 @@
266266
#texinfo_no_detailmenu = False
267267

268268
rst_prolog = '.. |...| unicode:: U+2026 .. ellipsis\n'
269+
270+
intersphinx_mapping = {
271+
'python': ('https://docs.python.org/3', None),
272+
'six': ('https://six.readthedocs.io', None),
273+
'attrs': ('http://www.attrs.org/en/stable', None),
274+
'cython': ('http://docs.cython.org/en/latest', None),
275+
'monkeytype': ('https://monkeytype.readthedocs.io/en/latest', None),
276+
}

docs/source/config_file.rst

Lines changed: 7 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -29,10 +29,9 @@ Config file format
2929
******************
3030

3131
The configuration file format is the usual
32-
`ini file <https://docs.python.org/3.6/library/configparser.html>`_
33-
format. It should contain section names in square brackets and flag
34-
settings of the form `NAME = VALUE`. Comments start with ``#``
35-
characters.
32+
:doc:`ini file <python:library/configparser>` format. It should contain
33+
section names in square brackets and flag settings of the form
34+
`NAME = VALUE`. Comments start with ``#`` characters.
3635

3736
- A section named ``[mypy]`` must be present. This specifies
3837
the global flags. The ``setup.cfg`` file is an exception to this.
@@ -357,7 +356,7 @@ a list of import discovery options that may be used
357356
:ref:`both per-module and globally <config-file-import-discovery-per-module>`.
358357

359358
``namespace_packages`` (bool, default False)
360-
Enables PEP 420 style namespace packages. See :ref:`the
359+
Enables :pep:`420` style namespace packages. See :ref:`the
361360
corresponding flag <import-discovery>` for more information.
362361

363362
``python_executable`` (string)
@@ -367,7 +366,7 @@ a list of import discovery options that may be used
367366
the executable used to run mypy.
368367

369368
``no_silence_site_packages`` (bool, default False)
370-
Enables reporting error messages generated within PEP 561 compliant packages.
369+
Enables reporting error messages generated within :pep:`561` compliant packages.
371370
Those error messages are suppressed by default, since you are usually
372371
not able to control errors in 3rd party code.
373372

@@ -379,9 +378,8 @@ a list of import discovery options that may be used
379378

380379
``files`` (string)
381380
A comma-separated list of paths which should be checked by mypy if none are given on the command
382-
line. Supports recursive file globbing using
383-
[the glob library](https://docs.python.org/3/library/glob.html), where `*` (e.g. `*.py`) matches
384-
files in the current directory and `**/` (e.g. `**/*.py`) matches files in any directories below
381+
line. Supports recursive file globbing using :doc:`library/glob`, where ``*`` (e.g. ``*.py``) matches
382+
files in the current directory and ``**/`` (e.g. ``**/*.py``) matches files in any directories below
385383
the current one. User home directory and environment variables will be expanded.
386384

387385

docs/source/error_code_list.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -542,8 +542,8 @@ Check instantiation of abstract classes [abstract]
542542

543543
Mypy generates an error if you try to instantiate an abstract base
544544
class (ABC). An abtract base class is a class with at least one
545-
abstract method or attribute. (See also `Python
546-
abc module documentation <https://docs.python.org/3/library/abc.html>`_.)
545+
abstract method or attribute. (See also :doc:`Python
546+
abc module documentation <python:library/abc>`)
547547

548548
Sometimes a class is made accidentally abstract, often due to an
549549
unimplemented abstract method. In a case like this you need to provide

docs/source/existing_code.rst

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,7 @@ These steps will get you started with mypy on an existing codebase:
2020

2121
5. Write annotations as you modify existing code and write new code
2222

23-
6. Use MonkeyType or PyAnnotate to automatically annotate legacy code
23+
6. Use :doc:`monkeytype:index` or `PyAnnotate`_ to automatically annotate legacy code
2424

2525
We discuss all of these points in some detail below, and a few optional
2626
follow-up steps.
@@ -145,8 +145,7 @@ Automate annotation of legacy code
145145

146146
There are tools for automatically adding draft annotations
147147
based on type profiles collected at runtime. Tools include
148-
`MonkeyType <https://github.com/Instagram/MonkeyType>`_
149-
(Python 3) and `PyAnnotate <https://github.com/dropbox/pyannotate>`_
148+
:doc:`monkeytype:index` (Python 3) and `PyAnnotate`_
150149
(type comments only).
151150

152151
A simple approach is to collect types from test runs. This may work
@@ -177,3 +176,5 @@ catch more bugs. For example, you can ask mypy to require annotations
177176
for all functions in certain modules to avoid accidentally introducing
178177
code that won't be type checked. Refer to :ref:`command-line` for the
179178
details.
179+
180+
.. _PyAnnotate: https://github.com/dropbox/pyannotate

docs/source/extending_mypy.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -43,12 +43,12 @@ Extending mypy using plugins
4343
Python is a highly dynamic language and has extensive metaprogramming
4444
capabilities. Many popular libraries use these to create APIs that may
4545
be more flexible and/or natural for humans, but are hard to express using
46-
static types. Extending the PEP 484 type system to accommodate all existing
46+
static types. Extending the :pep:`484` type system to accommodate all existing
4747
dynamic patterns is impractical and often just impossible.
4848

4949
Mypy supports a plugin system that lets you customize the way mypy type checks
5050
code. This can be useful if you want to extend mypy so it can type check code
51-
that uses a library that is difficult to express using just PEP 484 types.
51+
that uses a library that is difficult to express using just :pep:`484` types.
5252

5353
The plugin system is focused on improving mypy's understanding
5454
of *semantics* of third party frameworks. There is currently no way to define
@@ -139,7 +139,7 @@ Current list of plugin hooks
139139
****************************
140140

141141
**get_type_analyze_hook()** customizes behaviour of the type analyzer.
142-
For example, PEP 484 doesn't support defining variadic generic types:
142+
For example, :pep:`484` doesn't support defining variadic generic types:
143143

144144
.. code-block:: python
145145

docs/source/faq.rst

Lines changed: 4 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -88,8 +88,8 @@ the scope of the mypy project.
8888
How do I type check my Python 2 code?
8989
*************************************
9090

91-
You can use a `comment-based function annotation syntax
92-
<https://www.python.org/dev/peps/pep-0484/#suggested-syntax-for-python-2-7-and-straddling-code>`_
91+
You can use a :pep:`comment-based function annotation syntax
92+
<484#suggested-syntax-for-python-2-7-and-straddling-code>`
9393
and use the ``--py2`` command-line option to type check your Python 2 code.
9494
You'll also need to install ``typing`` for Python 2 via ``pip install typing``.
9595

@@ -131,8 +131,7 @@ may be more flexible if it is typed with protocols. Also, using protocol types
131131
removes the necessity to explicitly declare implementations of ABCs.
132132
As a rule of thumb, we recommend using nominal classes where possible, and
133133
protocols where necessary. For more details about protocol types and structural
134-
subtyping see :ref:`protocol-types` and
135-
`PEP 544 <https://www.python.org/dev/peps/pep-0544/>`_.
134+
subtyping see :ref:`protocol-types` and :pep:`544`.
136135

137136
I like Python and I have no need for static typing
138137
**************************************************
@@ -165,7 +164,7 @@ monkey patching of methods.
165164
How is mypy different from Cython?
166165
**********************************
167166

168-
`Cython <http://cython.org/>`_ is a variant of Python that supports
167+
`Cython :doc:<cython:index>` is a variant of Python that supports
169168
compilation to CPython C modules. It can give major speedups to
170169
certain classes of programs compared to CPython, and it provides
171170
static typing (though this is different from mypy). Mypy differs in

docs/source/generics.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -662,8 +662,8 @@ Type aliases can be generic. In this case they can be used in two ways:
662662
Subscripted aliases are equivalent to original types with substituted type
663663
variables, so the number of type arguments must match the number of free type variables
664664
in the generic type alias. Unsubscripted aliases are treated as original types with free
665-
variables replaced with ``Any``. Examples (following `PEP 484
666-
<https://www.python.org/dev/peps/pep-0484/#type-aliases>`_):
665+
variables replaced with ``Any``. Examples (following :pep:`PEP 484: Type aliases
666+
<484#type-aliases>`):
667667

668668
.. code-block:: python
669669

docs/source/getting_started.rst

Lines changed: 2 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -88,14 +88,12 @@ calls since the arguments have invalid types:
8888
greeting(b'Alice') # Argument 1 to "greeting" has incompatible type "bytes"; expected "str"
8989
9090
Note that this is all still valid Python 3 code! The function annotation syntax
91-
shown above was added to Python `as a part of Python 3.0 <pep3107_>`_.
91+
shown above was added to Python :pep:`as a part of Python 3.0 <3107>`.
9292

9393
If you are trying to type check Python 2 code, you can add type hints
9494
using a comment-based syntax instead of the Python 3 annotation syntax.
9595
See our section on :ref:`typing Python 2 code <python2>` for more details.
9696

97-
.. _pep3107: https://www.python.org/dev/peps/pep-3107/
98-
9997
Being able to pick whether you want a function to be dynamically or statically
10098
typed can be very helpful. For example, if you are migrating an existing
10199
Python codebase to use static types, it's usually easier to migrate by incrementally
@@ -286,7 +284,7 @@ for example, when assigning an empty dictionary to some global value:
286284
You can teach mypy what type ``my_global_dict`` is meant to have by giving it
287285
a type hint. For example, if you knew this variable is supposed to be a dict
288286
of ints to floats, you could annotate it using either variable annotations
289-
(introduced in Python 3.6 by `PEP 526 <pep526_>`_) or using a comment-based
287+
(introduced in Python 3.6 by :pep:`526`) or using a comment-based
290288
syntax like so:
291289

292290
.. code-block:: python
@@ -297,9 +295,6 @@ syntax like so:
297295
# If you want compatibility with older versions of Python
298296
my_global_dict = {} # type: Dict[int, float]
299297
300-
.. _pep526: https://www.python.org/dev/peps/pep-0526/
301-
302-
303298
.. _stubs-intro:
304299

305300
Library stubs and typeshed

docs/source/installed_packages.rst

Lines changed: 13 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -3,12 +3,12 @@
33
Using installed packages
44
========================
55

6-
`PEP 561 <https://www.python.org/dev/peps/pep-0561/>`__ specifies how to mark
7-
a package as supporting type checking. Below is a summary of how to create
8-
PEP 561 compatible packages and have mypy use them in type checking.
6+
:pep:`561` specifies how to mark a package as supporting type checking.
7+
Below is a summary of how to create :pep:`561` compatible packages and have
8+
mypy use them in type checking.
99

10-
Using PEP 561 compatible packages with mypy
11-
*******************************************
10+
Using :pep:`561` compatible packages with mypy
11+
**********************************************
1212

1313
Generally, you do not need to do anything to use installed packages that
1414
support typing for the Python executable used to run mypy. Note that most
@@ -30,17 +30,16 @@ imports and custom import hooks.
3030
If you do not want to use typed packages, use the ``--no-site-packages`` flag
3131
to disable searching.
3232

33-
Note that stub-only packages (defined in
34-
`PEP 561 <https://www.python.org/dev/peps/pep-0561/#stub-only-packages>`__)
35-
cannot be used with ``MYPYPATH``. If you want mypy to find the package, it must
36-
be installed. For a package ``foo``, the name of the stub-only package
37-
(``foo-stubs``) is not a legal package name, so mypy will not find it, unless
38-
it is installed.
33+
Note that stub-only packages (defined in :pep:`PEP 561: Stub-only Packages
34+
<561#stub-only-packages>`) cannot be used with ``MYPYPATH``. If you want mypy
35+
to find the package, it must be installed. For a package ``foo``, the name of
36+
the stub-only package (``foo-stubs``) is not a legal package name, so mypy
37+
will not find it, unless it is installed.
3938

40-
Making PEP 561 compatible packages
41-
**********************************
39+
Making :pep:`561` compatible packages
40+
*************************************
4241

43-
PEP 561 notes three main ways to distribute type information. The first is a
42+
:pep:`561` notes three main ways to distribute type information. The first is a
4443
package that has only inline type annotations in the code itself. The second is
4544
a package that ships :ref:`stub files <stub-files>` with type information
4645
alongside the runtime code. The third method, also known as a "stub only

0 commit comments

Comments
 (0)