Skip to content

Commit 55b5aed

Browse files
authored
Further caution against --follow-imports=skip (python#18048)
1 parent 38d26aa commit 55b5aed

File tree

1 file changed

+19
-8
lines changed

1 file changed

+19
-8
lines changed

docs/source/running_mypy.rst

Lines changed: 19 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -503,7 +503,7 @@ accepts one of four string values:
503503
main.py:1: note: (Using --follow-imports=error, module not passed on command line)
504504

505505
If you are starting a new codebase and plan on using type hints from
506-
the start, we recommend you use either :option:`--follow-imports=normal <mypy --follow-imports>`
506+
the start, we **recommend** you use either :option:`--follow-imports=normal <mypy --follow-imports>`
507507
(the default) or :option:`--follow-imports=error <mypy --follow-imports>`. Either option will help
508508
make sure you are not skipping checking any part of your codebase by
509509
accident.
@@ -514,16 +514,27 @@ files that do not use type hints) pass under :option:`--follow-imports=normal <m
514514
This is usually not too difficult to do: mypy is designed to report as
515515
few error messages as possible when it is looking at unannotated code.
516516

517-
Only if doing this is intractable, we recommend passing mypy just the files
518-
you want to type check and use :option:`--follow-imports=silent <mypy --follow-imports>`. Even if
519-
mypy is unable to perfectly type check a file, it can still glean some
517+
Only if doing this is intractable, try passing mypy just the files
518+
you want to type check and using :option:`--follow-imports=silent <mypy --follow-imports>`.
519+
Even if mypy is unable to perfectly type check a file, it can still glean some
520520
useful information by parsing it (for example, understanding what methods
521521
a given object has). See :ref:`existing-code` for more recommendations.
522522

523-
We do not recommend using ``skip`` unless you know what you are doing:
524-
while this option can be quite powerful, it can also cause many
525-
hard-to-debug errors.
526-
527523
Adjusting import following behaviour is often most useful when restricted to
528524
specific modules. This can be accomplished by setting a per-module
529525
:confval:`follow_imports` config option.
526+
527+
.. warning::
528+
529+
We do not recommend using ``follow_imports=skip`` unless you're really sure
530+
you know what you are doing. This option greatly restricts the analysis mypy
531+
can perform and you will lose a lot of the benefits of type checking.
532+
533+
This is especially true at the global level. Setting a per-module
534+
``follow_imports=skip`` for a specific problematic module can be
535+
useful without causing too much harm.
536+
537+
.. note::
538+
539+
If you're looking to resolve import errors related to libraries, try following
540+
the advice in :ref:`fix-missing-imports` before messing with ``follow_imports``.

0 commit comments

Comments
 (0)