]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
Issue #24029: Document the name binding behavior for submodule imports.
authorBarry Warsaw <barry@python.org>
Wed, 22 Apr 2015 22:38:26 +0000 (18:38 -0400)
committerBarry Warsaw <barry@python.org>
Wed, 22 Apr 2015 22:38:26 +0000 (18:38 -0400)
1  2 
Doc/reference/import.rst
Misc/NEWS

index dec5f8f14bca6b6384f4b513b90567c3da01cae5,7966bc5133370939af73fa95b1bfb34ccd9a08a1..50e46884a2e2dfd5938a72b75fafdf147970fb37
@@@ -460,14 -459,43 +460,49 @@@ import machinery will create the new mo
  
      * If loading fails, the loader must remove any modules it has inserted
        into :data:`sys.modules`, but it must remove **only** the failing
 -      module, and only if the loader itself has loaded it explicitly.
 +      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.
  
+ Submodules
+ ----------
+ When a submodule is loaded using any mechanism (e.g. ``importlib`` APIs, the
+ ``import`` or ``import-from`` statements, or built-in ``__import__()``) a
+ binding is placed in the parent module's namespace to the submodule object.
+ For example, if package ``spam`` has a submodule ``foo``, after importing
+ ``spam.foo``, ``spam`` will have an attribute ``foo`` which is bound to the
+ submodule.  Let's say you have the following directory structure::
+     spam/
+         __init__.py
+         foo.py
+         bar.py
+ and ``spam/__init__.py`` has the following lines in it::
+     from .foo import Foo
+     from .bar import Bar
+ then executing the following puts a name binding to ``foo`` and ``bar`` in the
+ ``spam`` module::
+     >>> import spam
+     >>> spam.foo
+     <module 'spam.foo' from '/tmp/imports/spam/foo.py'>
+     >>> spam.bar
+     <module 'spam.bar' from '/tmp/imports/spam/bar.py'>
+ Given Python's familiar name binding rules this might seem surprising, but
+ it's actually a fundamental feature of the import system.  The invariant
+ holding is that if you have ``sys.modules['spam']`` and
+ ``sys.modules['spam.foo']`` (as you would after the above import), the latter
+ must appear as the ``foo`` attribute of the former.
  Module spec
  -----------
  
diff --cc Misc/NEWS
index e50fe6484197be58afeadb786f0f398b3a7cb943,24b515f1b2d0abc21177bbd6d83b609c26a26a53..c295816b9a5760b8e2798ea418f53bb52ae34b24
+++ b/Misc/NEWS
@@@ -12,52 -12,6 +12,57 @@@ Core and Builtin
  
  - Issue #24022: Fix tokenizer crash when processing undecodable source code.
  
 +Library
 +-------
 +
 +- Issue #17445: add difflib.diff_bytes() to support comparison of
 +  byte strings (fixes a regression from Python 2).
 +
 +- Issue #23917: Fall back to sequential compilation when ProcessPoolExecutor
 +  doesn't exist.  Patch by Claudiu Popa.
 +
 +- Issue #23008: Fixed resolving attributes with boolean value is False in pydoc.
 +
 +- Fix asyncio issue 235: LifoQueue and PriorityQueue's put didn't
 +  increment unfinished tasks (this bug was introduced when
 +  JoinableQueue was merged with Queue).
 +
 +- Issue #23908: os functions now reject paths with embedded null character
 +  on Windows instead of silently truncate them.
 +
 +- Issue #23728: binascii.crc_hqx() could return an integer outside of the range
 +  0-0xffff for empty data.
 +
 +- Issue #23887: urllib.error.HTTPError now has a proper repr() representation. 
 +  Patch by Berker Peksag.
 +
++Documentation
++-------------
++
++- Issue #24029: Document the name binding behavior for submodule imports.
++
 +
 +What's New in Python 3.5.0 alpha 4?
 +===================================
 +
 +Release date: 2015-04-19
 +
 +Core and Builtins
 +-----------------
 +
 +- Issue #22980: Under Linux, GNU/KFreeBSD and the Hurd, C extensions now include
 +  the architecture triplet in the extension name, to make it easy to test builds
 +  for different ABIs in the same working tree.  Under OS X, the extension name
 +  now includes PEP 3149-style information.
 +
 +- Issue #22631: Added Linux-specific socket constant CAN_RAW_FD_FRAMES.
 +  Patch courtesy of Joe Jevnik.
 +
 +- Issue #23731: Implement PEP 488: removal of .pyo files.
 +
 +- Issue #23726: Don't enable GC for user subclasses of non-GC types that
 +  don't add any new fields.  Patch by Eugene Toder.
 +
  - Issue #23309: Avoid a deadlock at shutdown if a daemon thread is aborted
    while it is holding a lock to a buffered I/O object, and the main thread
    tries to use the same I/O object (typically stdout or stderr).  A fatal