]> granicus.if.org Git - python/commitdiff
Issue #23422: Clarify some things around importlib.import_module()
authorBrett Cannon <brett@python.org>
Fri, 20 Feb 2015 15:34:20 +0000 (10:34 -0500)
committerBrett Cannon <brett@python.org>
Fri, 20 Feb 2015 15:34:20 +0000 (10:34 -0500)
Doc/library/importlib.rst

index 9c6b280b83b46c27d3083064b7f656c8040d2e2c..e61ac351cddb929c9323eb893d0d2df075f9cb34 100644 (file)
@@ -69,6 +69,10 @@ Functions
 
     An implementation of the built-in :func:`__import__` function.
 
+    .. note::
+       Programmatic importing of modules should use :func:`import_module`
+       instead of this function.
+
 .. function:: import_module(name, package=None)
 
     Import a module. The *name* argument specifies what module to
@@ -81,12 +85,15 @@ Functions
 
     The :func:`import_module` function acts as a simplifying wrapper around
     :func:`importlib.__import__`. This means all semantics of the function are
-    derived from :func:`importlib.__import__`, including requiring the package
-    from which an import is occurring to have been previously imported
-    (i.e., *package* must already be imported). The most important difference
-    is that :func:`import_module` returns the specified package or module
-    (e.g. ``pkg.mod``), while :func:`__import__` returns the
-    top-level package or module (e.g. ``pkg``).
+    derived from :func:`importlib.__import__`. The most important difference
+    between these two functions is that :func:`import_module` returns the
+    specified package or module (e.g. ``pkg.mod``), while :func:`__import__`
+    returns the top-level package or module (e.g. ``pkg``).
+
+    If you are dynamically importing a module that was created since the
+    interpreter began execution (e.g., created a Python source file), you may
+    need to call :func:`invalidate_caches` in order for the new module to be
+    noticed by the import system.
 
     .. versionchanged:: 3.3
        Parent packages are automatically imported.