Skip to content

Commit 582a833

Browse files
authored
Miscellaneous doc updates (python#2460)
* Document additional command line options * Improve documentation of using Python 3.6 features * Document MYPY
1 parent 248a8e4 commit 582a833

File tree

3 files changed

+59
-18
lines changed

3 files changed

+59
-18
lines changed

docs/source/command_line.rst

Lines changed: 26 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -12,18 +12,20 @@ flag (or its long form ``--help``)::
1212
[-s] [--almost-silent] [--disallow-untyped-calls]
1313
[--disallow-untyped-defs] [--check-untyped-defs]
1414
[--disallow-subclassing-any] [--warn-incomplete-stub]
15-
[--warn-redundant-casts] [--warn-unused-ignores]
16-
[--hide-error-context] [--fast-parser] [-i] [--cache-dir DIR]
17-
[--strict-optional]
18-
[--strict-optional-whitelist [GLOB [GLOB ...]]] [--pdb]
19-
[--show-traceback] [--stats] [--inferstats]
20-
[--custom-typing MODULE] [--custom-typeshed-dir DIR]
21-
[--scripts-are-modules] [--config-file CONFIG_FILE]
22-
[--show-column-numbers] [--html-report DIR]
23-
[--linecount-report DIR] [--linecoverage-report DIR]
24-
[--memory-xml-report DIR] [--old-html-report DIR]
25-
[--txt-report DIR] [--xml-report DIR] [--xslt-html-report DIR]
26-
[--xslt-txt-report DIR] [-m MODULE] [-c PROGRAM_TEXT] [-p PACKAGE]
15+
[--warn-redundant-casts] [--warn-no-return]
16+
[--warn-unused-ignores] [--hide-error-context] [--fast-parser]
17+
[-i] [--cache-dir DIR] [--strict-optional]
18+
[--strict-optional-whitelist [GLOB [GLOB ...]]]
19+
[--junit-xml JUNIT_XML] [--pdb] [--show-traceback] [--stats]
20+
[--inferstats] [--custom-typing MODULE]
21+
[--custom-typeshed-dir DIR] [--scripts-are-modules]
22+
[--config-file CONFIG_FILE] [--show-column-numbers]
23+
[--find-occurrences CLASS.MEMBER] [--cobertura-xml-report DIR]
24+
[--html-report DIR] [--linecount-report DIR]
25+
[--linecoverage-report DIR] [--memory-xml-report DIR]
26+
[--old-html-report DIR] [--txt-report DIR] [--xml-report DIR]
27+
[--xslt-html-report DIR] [--xslt-txt-report DIR] [-m MODULE]
28+
[-c PROGRAM_TEXT] [-p PACKAGE]
2729
[files [files ...]]
2830

2931
(etc., too long to show everything here)
@@ -339,7 +341,18 @@ Here are some more useful flags:
339341
in the current directory. Settings override mypy's built-in defaults
340342
and command line flags can override settings. See :ref:`config-file`
341343
for the syntax of configuration files.
342-
344+
345+
- ``--junit-xml JUNIT_XML`` will make mypy generate a JUnit XML test
346+
result document with type checking results. This can make it easier
347+
to integrate mypy with continuous integration (CI) tools.
348+
349+
- ``--find-occurrences CLASS.MEMBER`` will make mypy print out all
350+
usages of a class member based on static type information. This
351+
feature is experimental.
352+
353+
- ``--cobertura-xml-report DIR`` causes mypy to generate a Cobertura
354+
XML type checking coverage report.
355+
343356
For the remaining flags you can read the full ``mypy -h`` output.
344357

345358
.. note::

docs/source/common_issues.rst

Lines changed: 17 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -299,7 +299,7 @@ Displaying the type of an expression
299299

300300
You can use ``reveal_type(expr)`` to ask mypy to display the inferred
301301
static type of an expression. This can be useful when you don't quite
302-
understand how mypy handles a particlar piece of code. Example:
302+
understand how mypy handles a particular piece of code. Example:
303303

304304
.. code-block:: python
305305
@@ -354,3 +354,19 @@ File ``bar.py``:
354354

355355
The ``TYPE_CHECKING`` constant defined by the ``typing`` module
356356
is ``False`` at runtime but ``True`` while type checking.
357+
358+
Python 3.5.1 doesn't have ``typing.TYPE_CHECKING``. An alternative is
359+
to define a constant named ``MYPY`` that has the value ``False``
360+
at runtime. Mypy considers it to be ``True`` when type checking.
361+
Here's the above example modified to use ``MYPY``:
362+
363+
.. code-block:: python
364+
365+
from typing import List
366+
367+
MYPY = False
368+
if MYPY:
369+
import bar
370+
371+
def listify(arg: 'bar.BarClass') -> 'List[bar.BarClass]':
372+
return [arg]

docs/source/python36.rst

Lines changed: 16 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,21 @@ support matrix for these in mypy (to be updated with each new mypy
1111
release). The intention is to support all of these by the time Python
1212
3.6 is released.
1313

14+
.. note::
15+
16+
Mypy only understands Python 3.6 syntax if you use the ``--fast-parser`` flag.
17+
This requires that the `typed_ast <https://pypi.python.org/pypi/typed-ast>`_ package is
18+
installed and has at least version 0.6.1. Use ``pip3 install -U typed_ast``.
19+
If running mypy on an earlier Python version, you also need to enable 3.6 support
20+
through ``--python-version 3.6``.
21+
22+
Example command line (or use :ref:`config-file`):
23+
24+
.. code-block:: text
25+
26+
$ pip3 install -U typed_ast
27+
$ mypy --fast-parser --python-version 3.6 program.py
28+
1429
Syntax for variable annotations (`PEP 526 <https://www.python.org/dev/peps/pep-0526>`_)
1530
---------------------------------------------------------------------------------------
1631

@@ -31,10 +46,7 @@ Mypy fully supports this syntax, interpreting them as equivalent to
3146
3247
.. note::
3348

34-
This requires the ``--fast-parser`` flag and it requires that the
35-
`typed_ast <https://pypi.python.org/pypi/typed-ast>`_ package is
36-
installed and has at least version 0.6.1. Use ``pip3 install -U typed_ast``.
37-
49+
See above for how to enable Python 3.6 syntax.
3850

3951
Literal string formatting (`PEP 498 <https://www.python.org/dev/peps/pep-0498>`_)
4052
---------------------------------------------------------------------------------

0 commit comments

Comments
 (0)