gh-148672: Document namespace subpackages inside regular packages (#1… · python/cpython@9ba2a89

GitHub

@@ -122,6 +122,12 @@ Importing ``parent.one`` will implicitly execute ``parent/__init__.py`` and

122122``parent.three`` will execute ``parent/two/__init__.py`` and

123123``parent/three/__init__.py`` respectively.

124124125+A subdirectory inside a regular package that does not contain an

126+``__init__.py`` file is treated as an implicit

127+:ref:`namespace package <reference-namespace-package>` (a "namespace

128+subpackage") rooted in that parent. See :pep:`420` for the underlying

129+specification.

130+125131126132.. _reference-namespace-package:

127133@@ -153,6 +159,12 @@ physically located next to ``parent/two``. In this case, Python will create a

153159namespace package for the top-level ``parent`` package whenever it or one of

154160its subpackages is imported.

155161162+Namespace packages may also be nested inside a regular package. When the

163+import system searches a regular package's ``__path__`` and encounters a

164+subdirectory that does not contain an ``__init__.py`` file, that

165+subdirectory becomes a :term:`portion` contributing to a namespace

166+subpackage of the enclosing regular package.

167+156168See also :pep:`420` for the namespace package specification.

157169158170