mirror of
https://github.com/python/cpython.git
synced 2026-06-04 16:50:51 +00:00
gh-148672: Document namespace subpackages inside regular packages (#150056)
This commit is contained in:
parent
59abdf8207
commit
9ba2a89179
1 changed files with 12 additions and 0 deletions
|
|
@ -122,6 +122,12 @@ Importing ``parent.one`` will implicitly execute ``parent/__init__.py`` and
|
|||
``parent.three`` will execute ``parent/two/__init__.py`` and
|
||||
``parent/three/__init__.py`` respectively.
|
||||
|
||||
A subdirectory inside a regular package that does not contain an
|
||||
``__init__.py`` file is treated as an implicit
|
||||
:ref:`namespace package <reference-namespace-package>` (a "namespace
|
||||
subpackage") rooted in that parent. See :pep:`420` for the underlying
|
||||
specification.
|
||||
|
||||
|
||||
.. _reference-namespace-package:
|
||||
|
||||
|
|
@ -153,6 +159,12 @@ physically located next to ``parent/two``. In this case, Python will create a
|
|||
namespace package for the top-level ``parent`` package whenever it or one of
|
||||
its subpackages is imported.
|
||||
|
||||
Namespace packages may also be nested inside a regular package. When the
|
||||
import system searches a regular package's ``__path__`` and encounters a
|
||||
subdirectory that does not contain an ``__init__.py`` file, that
|
||||
subdirectory becomes a :term:`portion` contributing to a namespace
|
||||
subpackage of the enclosing regular package.
|
||||
|
||||
See also :pep:`420` for the namespace package specification.
|
||||
|
||||
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue