@@ -366,40 +366,45 @@ How mypy determines fully qualified module names depends on if the options
366366:option: `--namespace-packages <mypy --namespace-packages> ` and
367367:option: `--explicit-package-bases <mypy --explicit-package-bases> ` are set.
368368
369- First, if :option: `--namespace-packages <mypy --namespace-packages> ` is off,
370- mypy will rely solely upon the presence of ``__init__.py[i] `` files to determine
371- the fully qualified module name. That is, mypy will crawl up the directory tree
372- for as long as it continues to find ``__init__.py `` (or ``__init__.pyi ``) files.
373-
374- Second, if :option: `--namespace-packages <mypy --namespace-packages> ` is on, but
375- :option: `--explicit-package-bases <mypy --explicit-package-bases> ` is off, mypy
376- will allow for the possibility that directories without ``__init__.py[i] `` are
377- packages. Specifically, mypy will look at all parent directories of the file and
378- use the location of the highest ``__init__.py[i] `` in the directory tree to
379- determine the top-level package.
380-
381- For example, say your directory tree consists solely of ``pkg/__init__.py `` and
382- ``pkg/a/b/c/d/mod.py ``. When determining ``mod.py ``'s fully qualified module
383- name, mypy will look at ``pkg/__init__.py `` and conclude that the associated
384- module name is ``pkg.a.b.c.d.mod ``.
385-
386- You'll notice that that method still relies on ``__init__.py ``. If you can't put
387- an ``__init__.py `` in your top-level package, but still wish to pass paths (as
388- opposed to packages or modules using the ``-p `` or ``-m `` flags),
389- :option: `--explicit-package-bases <mypy --explicit-package-bases> ` provides a
390- solution.
391-
392- Third, with :option: `--explicit-package-bases <mypy --explicit-package-bases> `,
393- mypy will locate the nearest parent directory that is a member of the
394- ``MYPYPATH `` environment variable, the :confval: `mypy_path ` config or is the
395- current working directory. mypy will then use the relative path to determine the
396- fully qualified module name.
397-
398- For example, say your directory tree consists solely of
399- ``src/namespace_pkg/mod.py ``. If you run the command following command, mypy
400- will correctly associate ``mod.py `` with ``namespace_pkg.mod ``::
401-
402- $ MYPYPATH=src mypy --namespace-packages --explicit-package-bases .
369+ 1. If :option: `--namespace-packages <mypy --namespace-packages> ` is off,
370+ mypy will rely solely upon the presence of ``__init__.py[i] `` files to
371+ determine the fully qualified module name. That is, mypy will crawl up the
372+ directory tree for as long as it continues to find ``__init__.py `` (or
373+ ``__init__.pyi ``) files.
374+
375+ For example, if your directory tree consists of ``pkg/subpkg/mod.py ``, mypy
376+ would require ``pkg/__init__.py `` and ``pkg/subpkg/__init__.py `` to exist in
377+ order correctly associate ``mod.py `` with ``pkg.subpkg.mod ``
378+
379+ 2. If :option: `--namespace-packages <mypy --namespace-packages> ` is on, but
380+ :option: `--explicit-package-bases <mypy --explicit-package-bases> ` is off,
381+ mypy will allow for the possibility that directories without
382+ ``__init__.py[i] `` are packages. Specifically, mypy will look at all parent
383+ directories of the file and use the location of the highest
384+ ``__init__.py[i] `` in the directory tree to determine the top-level package.
385+
386+ For example, say your directory tree consists solely of ``pkg/__init__.py ``
387+ and ``pkg/a/b/c/d/mod.py ``. When determining ``mod.py ``'s fully qualified
388+ module name, mypy will look at ``pkg/__init__.py `` and conclude that the
389+ associated module name is ``pkg.a.b.c.d.mod ``.
390+
391+ 3. You'll notice that the above case still relies on ``__init__.py ``. If
392+ you can't put an ``__init__.py `` in your top-level package, but still wish to
393+ pass paths (as opposed to packages or modules using the ``-p `` or ``-m ``
394+ flags), :option: `--explicit-package-bases <mypy --explicit-package-bases> `
395+ provides a solution.
396+
397+ With :option: `--explicit-package-bases <mypy --explicit-package-bases> `, mypy
398+ will locate the nearest parent directory that is a member of the ``MYPYPATH ``
399+ environment variable, the :confval: `mypy_path ` config or is the current
400+ working directory. mypy will then use the relative path to determine the
401+ fully qualified module name.
402+
403+ For example, say your directory tree consists solely of
404+ ``src/namespace_pkg/mod.py ``. If you run the command following command, mypy
405+ will correctly associate ``mod.py `` with ``namespace_pkg.mod ``::
406+
407+ $ MYPYPATH=src mypy --namespace-packages --explicit-package-bases .
403408
404409If you pass a file not ending in ``.py[i] ``, the module name assumed is
405410``__main__ `` (matching the behavior of the Python interpreter), unless
0 commit comments