Skip to content

Commit 7b0df28

Browse files
authored
Document per-module follow_imports more explicitly (#10845)
Helps with #10842, #10820 and others There have been a number of issues recently where having this spelt out a little more explicitly would help users. The introduction of --exclude also (pretty understandably) confuses users who don't realise mypy's recursive file discovery is a little separate from its dogged import following.
1 parent 2c876d5 commit 7b0df28

File tree

3 files changed

+20
-6
lines changed

3 files changed

+20
-6
lines changed

docs/source/command_line.rst

Lines changed: 10 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -62,10 +62,16 @@ for full details, see :ref:`running-mypy`.
6262
multiple files / directories / paths, you can combine expressions with
6363
``|``, e.g ``--exclude '/setup\.py$|/build/'``.
6464

65-
Note that this flag only affects recursive discovery, that is, when mypy is
66-
discovering files within a directory tree or submodules of a package to
67-
check. If you pass a file or module explicitly it will still be checked. For
68-
instance, ``mypy --exclude '/setup.py$' but_still_check/setup.py``.
65+
Note that this flag only affects recursive directory tree discovery, that
66+
is, when mypy is discovering files within a directory tree or submodules of
67+
a package to check. If you pass a file or module explicitly it will still be
68+
checked. For instance, ``mypy --exclude '/setup.py$'
69+
but_still_check/setup.py``.
70+
71+
In particular, ``--exclude`` does not affect mypy's :ref:`import following
72+
<follow-imports>`. You can use a per-module :confval:`follow_imports` config
73+
option to additionally avoid mypy from following imports and checking code
74+
you do not wish to be checked.
6975

7076
Note that mypy will never recursively discover files and directories named
7177
"site-packages", "node_modules" or "__pycache__", or those whose name starts

docs/source/config_file.rst

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -254,6 +254,10 @@ section of the command line docs.
254254
``error``. For explanations see the discussion for the
255255
:option:`--follow-imports <mypy --follow-imports>` command line flag.
256256

257+
Using this option in a per-module section (potentially with a wildcard,
258+
as described at the top of this page) is a good way to prevent mypy from
259+
checking portions of your code.
260+
257261
If this option is used in a per-module section, the module name should
258262
match the name of the *imported* module, not the module containing the
259263
import statement.
@@ -924,10 +928,10 @@ Instead of using a ``mypy.ini`` file, a ``pyproject.toml`` file (as specified by
924928

925929
* Boolean values should be all lower case
926930

927-
Please see the `TOML Documentation`_ for more details and information on
931+
Please see the `TOML Documentation`_ for more details and information on
928932
what is allowed in a ``toml`` file. See `PEP 518`_ for more information on the layout
929933
and structure of the ``pyproject.toml`` file.
930-
934+
931935
Example ``pyproject.toml``
932936
**************************
933937

docs/source/running_mypy.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -384,6 +384,10 @@ We do not recommend using ``skip`` unless you know what you are doing:
384384
while this option can be quite powerful, it can also cause many
385385
hard-to-debug errors.
386386

387+
Adjusting import following behaviour is often most useful when restricted to
388+
specific modules. This can be accomplished by setting a per-module
389+
:confval:`follow_imports` config option.
390+
387391

388392
.. _mapping-paths-to-modules:
389393

0 commit comments

Comments
 (0)