Skip to content

Commit d7268ee

Browse files
hoeflingJukkaL
authored andcommitted
Mypy command line options crossreferencing (#7802)
This is the follow-up of #7784. All options verbatim texts and :ref: usages are replaced with the :option: role.
1 parent e2d2c11 commit d7268ee

15 files changed

+69
-67
lines changed

docs/source/additional_features.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -286,7 +286,7 @@ run after starting or restarting the daemon.
286286

287287
The mypy daemon requires extra fine-grained dependency data in
288288
the cache files which aren't included by default. To use caching with
289-
the mypy daemon, use the ``--cache-fine-grained`` option in your CI
289+
the mypy daemon, use the :option:`--cache-fine-grained <mypy --cache-fine-grained>` option in your CI
290290
build::
291291

292292
$ mypy --cache-fine-grained <args...>
@@ -326,7 +326,7 @@ at least if your codebase is hundreds of thousands of lines or more:
326326
network), the script can still fall back to a normal incremental build.
327327

328328
* You can have multiple local cache directories for different local branches
329-
using the ``--cache-dir`` option. If the user switches to an existing
329+
using the :option:`--cache-dir <mypy --cache-dir>` option. If the user switches to an existing
330330
branch where downloaded cache data is already available, you can continue
331331
to use the existing cache data instead of redownloading the data.
332332

docs/source/command_line.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ The mypy command line
66
=====================
77

88
This section documents mypy's command line interface. You can view
9-
a quick summary of the available flags by running ``mypy --help``.
9+
a quick summary of the available flags by running :option:`mypy --help`.
1010

1111
.. note::
1212

@@ -44,7 +44,7 @@ for full details, see :ref:`running-mypy`.
4444
package. This flag is identical to :option:`--module` apart from this
4545
behavior.
4646

47-
.. option -c PROGRAM_TEXT, --command PROGRAM_TEXT
47+
.. option:: -c PROGRAM_TEXT, --command PROGRAM_TEXT
4848

4949
Asks mypy to type check the provided string as a program.
5050

@@ -523,7 +523,7 @@ of the above sections.
523523
.. option:: --strict
524524

525525
This flag mode enables all optional error checking flags. You can see the
526-
list of flags enabled by strict mode in the full ``mypy --help`` output.
526+
list of flags enabled by strict mode in the full :option:`mypy --help` output.
527527

528528
Note: the exact list of flags enabled by running :option:`--strict` may change
529529
over time.

docs/source/common_issues.rst

Lines changed: 13 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ flagged as an error.
3131
return type) are not type-checked, and even the most blatant type
3232
errors (e.g. ``2 + 'a'``) pass silently. The solution is to add
3333
annotations. Where that isn't possible, functions without annotations
34-
can be checked using ``--check-untyped-defs``.
34+
can be checked using :option:`--check-untyped-defs <mypy --check-untyped-defs>`.
3535

3636
Example:
3737

@@ -73,17 +73,17 @@ flagged as an error.
7373
<https://github.com/python/typeshed/issues/285>`_ for the reason).
7474

7575
- **Some imports may be silently ignored**. Another source of
76-
unexpected ``Any`` values are the :ref:`"--ignore-missing-imports"
77-
<ignore-missing-imports>` and :ref:`"--follow-imports=skip"
78-
<follow-imports>` flags. When you use ``--ignore-missing-imports``,
76+
unexpected ``Any`` values are the :option:`--ignore-missing-imports
77+
<mypy --ignore-missing-imports>` and :option:`--follow-imports=skip
78+
<mypy --follow-imports>` flags. When you use :option:`--ignore-missing-imports <mypy --ignore-missing-imports>`,
7979
any imported module that cannot be found is silently replaced with
80-
``Any``. When using ``--follow-imports=skip`` the same is true for
80+
``Any``. When using :option:`--follow-imports=skip <mypy --follow-imports>` the same is true for
8181
modules for which a ``.py`` file is found but that are not specified
8282
on the command line. (If a ``.pyi`` stub is found it is always
8383
processed normally, regardless of the value of
84-
``--follow-imports``.) To help debug the former situation (no
85-
module found at all) leave out ``--ignore-missing-imports``; to get
86-
clarity about the latter use ``--follow-imports=error``. You can
84+
:option:`--follow-imports <mypy --follow-imports>`.) To help debug the former situation (no
85+
module found at all) leave out :option:`--ignore-missing-imports <mypy --ignore-missing-imports>`; to get
86+
clarity about the latter use :option:`--follow-imports=error <mypy --follow-imports>`. You can
8787
read up about these and other useful flags in :ref:`command-line`.
8888

8989
- **A function annotated as returning a non-optional type returns 'None'
@@ -418,7 +418,7 @@ Example:
418418
419419
Some other expressions exhibit similar behavior; in particular,
420420
:py:data:`~typing.TYPE_CHECKING`, variables named ``MYPY``, and any variable
421-
whose name is passed to ``--always-true`` or ``--always-false``.
421+
whose name is passed to :option:`--always-true <mypy --always-true>` or :option:`--always-false <mypy --always-false>`.
422422
(However, ``True`` and ``False`` are not treated specially!)
423423

424424
.. note::
@@ -431,14 +431,14 @@ By default, mypy will use your current version of Python and your current
431431
operating system as default values for ``sys.version_info`` and
432432
``sys.platform``.
433433

434-
To target a different Python version, use the ``--python-version X.Y`` flag.
434+
To target a different Python version, use the :option:`--python-version X.Y <mypy --python-version>` flag.
435435
For example, to verify your code typechecks if were run using Python 2, pass
436-
in ``--python-version 2.7`` from the command line. Note that you do not need
436+
in :option:`--python-version 2.7 <mypy --python-version>` from the command line. Note that you do not need
437437
to have Python 2.7 installed to perform this check.
438438

439-
To target a different operating system, use the ``--platform PLATFORM`` flag.
439+
To target a different operating system, use the :option:`--platform PLATFORM <mypy --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 :py:data:`sys.platform`
441+
in :option:`--platform win32 <mypy --platform>`. See the documentation for :py:data:`sys.platform`
442442
for examples of valid platform parameters.
443443

444444
.. _reveal-type:

docs/source/config_file.rst

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -7,11 +7,11 @@ Mypy supports reading configuration settings from a file. By default
77
it uses the file ``mypy.ini`` with fallback to ``setup.cfg`` in the current
88
directory, then ``$XDG_CONFIG_HOME/mypy/config``, then
99
``~/.config/mypy/config``, and finally ``.mypy.ini`` in the user home directory
10-
if none of them are found; the ``--config-file`` command-line flag can be used
11-
to read a different file instead (see :ref:`--config-file <config-file-flag>`).
10+
if none of them are found; the :option:`--config-file <mypy --config-file>` command-line flag can be used
11+
to read a different file instead (see :ref:`config-file-flag`).
1212

1313
It is important to understand that there is no merging of configuration
14-
files, as it would lead to ambiguity. The ``--config-file`` flag
14+
files, as it would lead to ambiguity. The :option:`--config-file <mypy --config-file>` flag
1515
has the highest precedence and must be correct; otherwise mypy will report
1616
an error and exit. Without command line option, mypy will look for defaults,
1717
but will use only one of them. The first one to read is ``mypy.ini``,
@@ -134,7 +134,7 @@ This config file specifies three global options in the ``[mypy]`` section. These
134134
options will:
135135

136136
1. Type-check your entire project assuming it will be run using Python 2.7.
137-
(This is equivalent to using the ``--python-version 2.7`` or ``--2`` flag).
137+
(This is equivalent to using the :option:`--python-version 2.7 <mypy --python-version>` or :option:`-2 <mypy -2>` flag).
138138

139139
2. Report an error whenever a function returns a value that is inferred
140140
to have type ``Any``.

docs/source/error_code_list2.rst

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -18,7 +18,7 @@ error codes that are enabled by default.
1818
Check that type arguments exist [type-arg]
1919
------------------------------------------
2020

21-
If you use ``--disallow-any-generics``, mypy requires that each generic
21+
If you use :option:`--disallow-any-generics <mypy --disallow-any-generics>`, mypy requires that each generic
2222
type has values for each type argument. For example, the types ``List`` or
2323
``dict`` would be rejected. You should instead use types like ``List[int]`` or
2424
``Dict[str, int]``. Any omitted generic type arguments get implicit ``Any``
@@ -39,7 +39,7 @@ Example:
3939
Check that every function has an annotation [no-untyped-def]
4040
------------------------------------------------------------
4141

42-
If you use ``--disallow-untyped-defs``, mypy requires that all functions
42+
If you use :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`, mypy requires that all functions
4343
have annotations (either a Python 3 annotation or a type comment).
4444

4545
Example:
@@ -67,7 +67,7 @@ Example:
6767
Check that cast is not redundant [redundant-cast]
6868
-------------------------------------------------
6969

70-
If you use ``--warn-redundant-casts``, mypy will generate an error if the source
70+
If you use :option:`--warn-redundant-casts <mypy --warn-redundant-casts>`, mypy will generate an error if the source
7171
type of a cast is the same as the target type.
7272

7373
Example:
@@ -87,7 +87,7 @@ Example:
8787
Check that comparisons are overlapping [comparison-overlap]
8888
-----------------------------------------------------------
8989

90-
If you use ``--strict-equality``, mypy will generate an error if it
90+
If you use :option:`--strict-equality <mypy --strict-equality>`, mypy will generate an error if it
9191
thinks that a comparison operation is always true or false. These are
9292
often bugs. Sometimes mypy is too picky and the comparison can
9393
actually be useful. Instead of disabling strict equality checking
@@ -118,7 +118,7 @@ literal:
118118
Check that no untyped functions are called [no-untyped-call]
119119
------------------------------------------------------------
120120

121-
If you use ``--disallow-untyped-calls``, mypy generates an error when you
121+
If you use :option:`--disallow-untyped-calls <mypy --disallow-untyped-calls>`, mypy generates an error when you
122122
call an unannotated function in an annotated function.
123123

124124
Example:
@@ -138,7 +138,7 @@ Example:
138138
Check that function does not return Any value [no-any-return]
139139
-------------------------------------------------------------
140140

141-
If you use ``--warn-return-any``, mypy generates an error if you return a
141+
If you use :option:`--warn-return-any <mypy --warn-return-any>`, mypy generates an error if you return a
142142
value with an ``Any`` type in a function that is annotated to return a
143143
non-``Any`` value.
144144

@@ -158,7 +158,7 @@ Example:
158158
Check that types have no Any components due to missing imports [no-any-unimported]
159159
----------------------------------------------------------------------------------
160160

161-
If you use ``--disallow-any-unimported``, mypy generates an error if a component of
161+
If you use :option:`--disallow-any-unimported <mypy --disallow-any-unimported>`, mypy generates an error if a component of
162162
a type becomes ``Any`` because mypy couldn't resolve an import. These "stealth"
163163
``Any`` types can be surprising and accidentally cause imprecise type checking.
164164

docs/source/error_codes.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ Error codes may change in future mypy releases.
2323
Displaying error codes
2424
----------------------
2525

26-
Error codes are not displayed by default. Use ``--show-error-codes``
26+
Error codes are not displayed by default. Use :option:`--show-error-codes <mypy --show-error-codes>`
2727
to display error codes. Error codes are shown inside square brackets:
2828

2929
.. code-block:: text
@@ -43,7 +43,7 @@ codes on individual lines using this comment.
4343
.. note::
4444

4545
There are command-line flags and config file settings for enabling
46-
certain optional error codes, such as ``--disallow-untype-defs``,
46+
certain optional error codes, such as :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`,
4747
which enables the ``no-untyped-def`` error code.
4848

4949
This example shows how to ignore an error about an imported name mypy

docs/source/faq.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -90,7 +90,7 @@ How do I type check my Python 2 code?
9090

9191
You can use a :pep:`comment-based function annotation syntax
9292
<484#suggested-syntax-for-python-2-7-and-straddling-code>`
93-
and use the ``--py2`` command-line option to type check your Python 2 code.
93+
and use the :option:`--py2 <mypy --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

9696
Is mypy free?

docs/source/getting_started.rst

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ to your code to take full advantage of mypy. See the section below for details.
4242
.. note::
4343

4444
Although you must install Python 3 to run mypy, mypy is fully capable of
45-
type checking Python 2 code as well: just pass in the ``--py2`` flag. See
45+
type checking Python 2 code as well: just pass in the :option:`--py2 <mypy --py2>` flag. See
4646
:ref:`python2` for more details.
4747

4848
.. code-block:: shell
@@ -102,7 +102,7 @@ when you are prototyping a new feature, it may be convenient to initially implem
102102
the code using dynamic typing and only add type hints later once the code is more stable.
103103

104104
Once you are finished migrating or prototyping your code, you can make mypy warn you
105-
if you add a dynamic function by mistake by using the ``--disallow-untyped-defs``
105+
if you add a dynamic function by mistake by using the :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`
106106
flag. See :ref:`command-line` for more information on configuring mypy.
107107

108108
.. note::
@@ -333,11 +333,11 @@ mypy behaves: see :ref:`command-line` for more details.
333333
For example, suppose you want to make sure *all* functions within your
334334
codebase are using static typing and make mypy report an error if you
335335
add a dynamically-typed function by mistake. You can make mypy do this
336-
by running mypy with the ``--disallow-untyped-defs`` flag.
336+
by running mypy with the :option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>` flag.
337337

338-
Another potentially useful flag is ``--strict``, which enables many
338+
Another potentially useful flag is :option:`--strict <mypy --strict>`, which enables many
339339
(though not all) of the available strictness options -- including
340-
``--disallow-untyped-defs``.
340+
:option:`--disallow-untyped-defs <mypy --disallow-untyped-defs>`.
341341

342342
This flag is mostly useful if you're starting a new project from scratch
343343
and want to maintain a high degree of type safety from day one. However,

docs/source/installed_packages.rst

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -19,15 +19,15 @@ By default, mypy searches for packages installed for the Python executable
1919
running mypy. It is highly unlikely you want this situation if you have
2020
installed typed packages in another Python's package directory.
2121

22-
Generally, you can use the ``--python-version`` flag and mypy will try to find
22+
Generally, you can use the :option:`--python-version <mypy --python-version>` flag and mypy will try to find
2323
the correct package directory. If that fails, you can use the
24-
``--python-executable`` flag to point to the exact executable, and mypy will
24+
:option:`--python-executable <mypy --python-executable>` flag to point to the exact executable, and mypy will
2525
find packages installed for that Python executable.
2626

2727
Note that mypy does not support some more advanced import features, such as zip
2828
imports and custom import hooks.
2929

30-
If you do not want to use typed packages, use the ``--no-site-packages`` flag
30+
If you do not want to use typed packages, use the :option:`--no-site-packages <mypy --no-site-packages>` flag
3131
to disable searching.
3232

3333
Note that stub-only packages (defined in :pep:`PEP 561: Stub-only Packages

docs/source/kinds_of_types.rst

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -402,7 +402,7 @@ case you should add an explicit ``Optional[...]`` annotation (or type comment).
402402
``Optional[...]`` *does not* mean a function argument with a default value.
403403
However, if the default value of an argument is ``None``, you can use
404404
an optional type for the argument, but it's not enforced by default.
405-
You can use the ``--no-implicit-optional`` command-line option to stop
405+
You can use the :option:`--no-implicit-optional <mypy --no-implicit-optional>` command-line option to stop
406406
treating arguments with a ``None`` default value as having an implicit
407407
``Optional[...]`` type. It's possible that this will become the default
408408
behavior in the future.
@@ -418,7 +418,7 @@ the Java ``null``). In this mode ``None`` is also valid for primitive
418418
types such as ``int`` and ``float``, and :py:data:`~typing.Optional` types are
419419
not required.
420420

421-
The mode is enabled through the ``--no-strict-optional`` command-line
421+
The mode is enabled through the :option:`--no-strict-optional <mypy --no-strict-optional>` command-line
422422
option. In mypy versions before 0.600 this was the default mode. You
423423
can enable this option explicitly for backward compatibility with
424424
earlier mypy versions, in case you don't want to introduce optional

docs/source/more_types.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -535,7 +535,7 @@ type hints provided on the implementation. For example, in the
535535
argument list ``index: Union[int, slice]`` and a return type of
536536
``Union[T, Sequence[T]]``. If there are no annotations on the
537537
implementation, then the body is not type checked. If you want to
538-
force mypy to check the body anyways, use the ``--check-untyped-defs``
538+
force mypy to check the body anyways, use the :option:`--check-untyped-defs <mypy --check-untyped-defs>`
539539
flag (:ref:`more details here <untyped-definitions-and-calls>`).
540540

541541
The variants must also also be compatible with the implementation

docs/source/mypy_daemon.rst

Lines changed: 7 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,7 @@
11
.. _mypy_daemon:
22

3+
.. program:: dmypy
4+
35
Mypy daemon (mypy server)
46
=========================
57

@@ -41,8 +43,8 @@ will always run on the current host. Example::
4143
dmypy run -- --follow-imports=error prog.py pkg1/ pkg2/
4244

4345
.. note::
44-
You'll need to use either the ``--follow-imports=error`` or the
45-
``--follow-imports=skip`` option with dmypy because the current
46+
You'll need to use either the :option:`--follow-imports=error <mypy --follow-imports>` or the
47+
:option:`--follow-imports=skip <mypy --follow-imports>` option with dmypy because the current
4648
implementation can't follow imports.
4749
See :ref:`follow-imports` for details on how these work.
4850
You can also define these using a
@@ -53,7 +55,7 @@ configuration or mypy version changes.
5355

5456
You need to provide all files or directories you want to type check
5557
(other than stubs) as arguments. This is a result of the
56-
``--follow-imports`` restriction mentioned above.
58+
:option:`--follow-imports <mypy --follow-imports>` restriction mentioned above.
5759

5860
The initial run will process all the code and may take a while to
5961
finish, but subsequent runs will be quick, especially if you've only
@@ -95,8 +97,8 @@ command-specific options.
9597
Limitations
9698
***********
9799

98-
* You have to use either the ``--follow-imports=error`` or
99-
the ``--follow-imports=skip`` option because of an implementation
100+
* You have to use either the :option:`--follow-imports=error <mypy --follow-imports>` or
101+
the :option:`--follow-imports=skip <mypy --follow-imports>` option because of an implementation
100102
limitation. This can be defined
101103
through the command line or through a
102104
:ref:`configuration file <config-file>`.

docs/source/python2.rst

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -8,7 +8,7 @@ annotations are given in comments, since the function annotation
88
syntax was introduced in Python 3. The comment-based syntax is
99
specified in :pep:`484`.
1010

11-
Run mypy in Python 2 mode by using the ``--py2`` option::
11+
Run mypy in Python 2 mode by using the :option:`--py2 <mypy --py2>` option::
1212

1313
$ mypy --py2 program.py
1414

0 commit comments

Comments
 (0)