]> granicus.if.org Git - python/commitdiff
[3.6] bpo-31799: Make module.__spec__ more discoverable (GH-4010) (#4021)
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>
Tue, 17 Oct 2017 19:59:21 +0000 (12:59 -0700)
committerBarry Warsaw <barry@python.org>
Tue, 17 Oct 2017 19:59:21 +0000 (15:59 -0400)
bpo-31799: Make module.__spec__ more discoverable
(cherry picked from commit 191e3138200906e43cba9347177914325b54843f)

Doc/library/importlib.rst
Doc/reference/import.rst

index 6406e306c49faa3e103b34846183098c670d46a5..d194362fb003c25abbf5a564f1922102a8a557b5 100644 (file)
@@ -1045,7 +1045,15 @@ find and load modules.
 
 .. class:: ModuleSpec(name, loader, *, origin=None, loader_state=None, is_package=None)
 
-   A specification for a module's import-system-related state.
+   A specification for a module's import-system-related state.  This is
+   typically exposed as the module's ``__spec__`` attribute.  In the
+   descriptions below, the names in parentheses give the corresponding
+   attribute available directly on the module object.
+   E.g. ``module.__spec__.origin == module.__file__``.  Note however that
+   while the *values* are usually equivalent, they can differ since there is
+   no synchronization between the two objects.  Thus it is possible to update
+   the module's ``__path__`` at runtime, and this will not be automatically
+   reflected in ``__spec__.submodule_search_locations``.
 
    .. versionadded:: 3.4
 
index 8cf16cad4c9c9c94ddd8792532d6dca6ff0c8ab2..7fbf8ed9d789a4487956915ac95f17035cb18992 100644 (file)
@@ -519,8 +519,9 @@ and the loader that executes it.  Most importantly, it allows the
 import machinery to perform the boilerplate operations of loading,
 whereas without a module spec the loader had that responsibility.
 
-See :class:`~importlib.machinery.ModuleSpec` for more specifics on what
-information a module's spec may hold.
+The module's spec is exposed as the ``__spec__`` attribute on a module object.
+See :class:`~importlib.machinery.ModuleSpec` for details on the contents of
+the module spec.
 
 .. versionadded:: 3.4