Skip to content

Commit bb16ae1

Browse files
committed
Rewrite NamespacePath's doc
Signed-off-by: Filipe Laíns <[email protected]>
1 parent be415ab commit bb16ae1

File tree

1 file changed

+23
-4
lines changed

1 file changed

+23
-4
lines changed

Doc/library/importlib.rst

Lines changed: 23 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -1015,14 +1015,33 @@ find and load modules.
10151015

10161016
.. class:: NamespacePath(name, path, path_finder)
10171017

1018-
Represents a namespace package's path.
1018+
Represents a :term:`namespace package`'s path (:attr:`module.__path__`).
10191019

1020-
It uses the module *name* to find its parent module, and from there it looks
1021-
up the parent's :attr:`module.__path__`. When this changes, the module's own
1022-
path is recomputed, using *path_finder*. The initial value is set to *path*.
1020+
When its value is accessed, if necessary, it will be recomputed.
1021+
This keeps it in-sync with the global state (:attr:`sys.modules`).
1022+
1023+
The *name* argument is the name of the namespace module.
1024+
1025+
The *path* argument is the initial path value.
1026+
1027+
The *path_finder* argument is the callable used to recompute the path value.
1028+
It has the same signature as :meth:`MetaPathFinder.find_spec`.
1029+
1030+
When the parent's :attr:`module.__path__` attribute is updated, the path
1031+
value is recomputed.
1032+
1033+
If the parent module is missing from :data:`sys.modules`, then
1034+
:exc:`ModuleNotFoundError` will be raised.
10231035

10241036
For top-level modules, the parent module's path is :data:`sys.path`.
10251037

1038+
.. note::
1039+
1040+
:meth:`PathFinder.invalidate_caches` invalidates :class:`NamespacePath`s,
1041+
forcing the path value to be recomputed next time it is accessed.
1042+
1043+
.. versionadded:: next
1044+
10261045
10271046
.. class:: SourceFileLoader(fullname, path)
10281047

0 commit comments

Comments
 (0)