Skip to content

Commit 3eabedd

Browse files
gvanrossumGuido van Rossum
authored and
Guido van Rossum
committed
Add docs for --namespace-packages (#5749)
Follow-up for #5691. Should be cherry-picked into the release (#5741). Fixes #5757.
1 parent e12be3b commit 3eabedd

File tree

2 files changed

+24
-0
lines changed

2 files changed

+24
-0
lines changed

docs/source/command_line.rst

Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -72,6 +72,24 @@ Import discovery
7272
The following flags customize how exactly mypy discovers and follows
7373
imports.
7474

75+
``--namespace-packages``
76+
This flag enables import discovery to use namespace packages (see
77+
`PEP 420`_). In particular, this allows discovery of imported
78+
packages that don't have an ``__init__.py`` (or ``__init__.pyi``)
79+
file.
80+
81+
Namespace packages are found (using the PEP 420 rules, which
82+
prefers "classic" packages over namespace packages) along the
83+
module search path -- this is primarily set from the source files
84+
passed on the command line, the ``MYPYPATH`` environment variable,
85+
and the :ref:`mypy_path config option
86+
<config-file-import-discovery-global>`.
87+
88+
Note that this only affects import discovery -- for modules and
89+
packages explicitly passed on the command line, mypy still
90+
searches for ``__init__.py[i]`` files in order to determine the
91+
fully-qualified module/package name.
92+
7593
``--ignore-missing-imports``
7694
This flag makes mypy ignore all missing imports. It is equivalent
7795
to adding ``# type: ignore`` comments to all unresolved imports
@@ -570,6 +588,8 @@ Miscellaneous
570588
have many scripts that import a large package, the behavior enabled
571589
by this flag is often more convenient.)
572590

591+
.. _PEP 420: https://www.python.org/dev/peps/pep-0420/
592+
573593
.. _PEP 561: https://www.python.org/dev/peps/pep-0561/
574594

575595
.. _lxml: https://pypi.org/project/lxml/

docs/source/config_file.rst

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -304,6 +304,10 @@ Note: this section describes only global-only import discovery options. See abov
304304
a list of import discovery options that may be used
305305
:ref:`both per-module and globally <config-file-import-discovery-per-module>`.
306306

307+
``namespace_packages`` (bool, default False)
308+
Enables PEP 420 style namespace packages. See :ref:`the
309+
corresponding flag <import-discovery>` for more information.
310+
307311
``python_executable`` (string)
308312
Specifies the path to the Python executable to inspect to collect
309313
a list of available :ref:`PEP 561 packages <installed-packages>`. Defaults to

0 commit comments

Comments
 (0)