summaryrefslogtreecommitdiffstats
path: root/Doc/reference/import.rst
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2015-01-09 16:39:21 (GMT)
committerBrett Cannon <brett@python.org>2015-01-09 16:39:21 (GMT)
commit02d845400275076ef5ba2791c74b7670ac21f8a9 (patch)
tree36077086a1bd393ede07d99c61ed7137bd5bdcc3 /Doc/reference/import.rst
parent863c69cfebcafbf97ba401e0f3cd5cb077e0e8f2 (diff)
downloadcpython-02d845400275076ef5ba2791c74b7670ac21f8a9.zip
cpython-02d845400275076ef5ba2791c74b7670ac21f8a9.tar.gz
cpython-02d845400275076ef5ba2791c74b7670ac21f8a9.tar.bz2
Issue #23014: Make importlib.abc.Loader.create_module() required when
importlib.abc.Loader.exec_module() is also defined. Before this change, create_module() was optional **and** could return None to trigger default semantics. This change now reduces the options for choosing default semantics to one and in the most backporting-friendly way (define create_module() to return None).
Diffstat (limited to 'Doc/reference/import.rst')
-rw-r--r--Doc/reference/import.rst8
1 files changed, 7 insertions, 1 deletions
diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst
index 99b77be..2d60e62 100644
--- a/Doc/reference/import.rst
+++ b/Doc/reference/import.rst
@@ -339,6 +339,7 @@ of what happens during the loading portion of import::
module = None
if spec.loader is not None and hasattr(spec.loader, 'create_module'):
+ # It is assumed 'exec_module' will also be defined on the loader.
module = spec.loader.create_module(spec)
if module is None:
module = ModuleType(spec.name)
@@ -427,7 +428,7 @@ Module loaders may opt in to creating the module object during loading
by implementing a :meth:`~importlib.abc.Loader.create_module` method.
It takes one argument, the module spec, and returns the new module object
to use during loading. ``create_module()`` does not need to set any attributes
-on the module object. If the loader does not define ``create_module()``, the
+on the module object. If the method returns ``None``, the
import machinery will create the new module itself.
.. versionadded:: 3.4
@@ -462,6 +463,11 @@ import machinery will create the new module itself.
module(s), and only if the loader itself has loaded the module(s)
explicitly.
+.. versionchanged:: 3.5
+ A :exc:`DeprecationWarning` is raised when ``exec_module()`` is defined but
+ ``create_module()`` is not. Starting in Python 3.6 it will be an error to not
+ define ``create_module()`` on a loader attached to a ModuleSpec.
+
Module spec
-----------