Skip to content

Commit 191e313

Browse files
authored
bpo-31799: Make module.__spec__ more discoverable (#4010)
bpo-31799: Make module.__spec__ more discoverable
1 parent 6cfa927 commit 191e313

File tree

2 files changed

+12
-3
lines changed

2 files changed

+12
-3
lines changed

Doc/library/importlib.rst

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1048,7 +1048,15 @@ find and load modules.
10481048

10491049
.. class:: ModuleSpec(name, loader, *, origin=None, loader_state=None, is_package=None)
10501050

1051-
A specification for a module's import-system-related state.
1051+
A specification for a module's import-system-related state. This is
1052+
typically exposed as the module's ``__spec__`` attribute. In the
1053+
descriptions below, the names in parentheses give the corresponding
1054+
attribute available directly on the module object.
1055+
E.g. ``module.__spec__.origin == module.__file__``. Note however that
1056+
while the *values* are usually equivalent, they can differ since there is
1057+
no synchronization between the two objects. Thus it is possible to update
1058+
the module's ``__path__`` at runtime, and this will not be automatically
1059+
reflected in ``__spec__.submodule_search_locations``.
10521060

10531061
.. versionadded:: 3.4
10541062

Doc/reference/import.rst

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -519,8 +519,9 @@ and the loader that executes it. Most importantly, it allows the
519519
import machinery to perform the boilerplate operations of loading,
520520
whereas without a module spec the loader had that responsibility.
521521

522-
See :class:`~importlib.machinery.ModuleSpec` for more specifics on what
523-
information a module's spec may hold.
522+
The module's spec is exposed as the ``__spec__`` attribute on a module object.
523+
See :class:`~importlib.machinery.ModuleSpec` for details on the contents of
524+
the module spec.
524525

525526
.. versionadded:: 3.4
526527

0 commit comments

Comments
 (0)