[Python-checkins] cpython (merge 3.4 -> default): Issue #19697: merge docs from 3.4
nick.coghlan
python-checkins at python.org
Sat Mar 29 06:41:36 CET 2014
http://hg.python.org/cpython/rev/a90254be2da2
changeset: 90022:a90254be2da2
parent: 90020:bca58d3cf035
parent: 90021:0427c2ff653d
user: Nick Coghlan <ncoghlan at gmail.com>
date: Sat Mar 29 15:41:18 2014 +1000
summary:
Issue #19697: merge docs from 3.4
files:
Doc/reference/import.rst | 18 ++++++++++++++++--
1 files changed, 16 insertions(+), 2 deletions(-)
diff --git a/Doc/reference/import.rst b/Doc/reference/import.rst
--- a/Doc/reference/import.rst
+++ b/Doc/reference/import.rst
@@ -852,16 +852,30 @@
gets set appropriately or to ``None``.
When Python is started with the :option:`-m` option, ``__spec__`` is set
-to the module spec of the corresponding module.
+to the module spec of the corresponding module or package. ``__spec__`` is
+also populated when the ``__main__`` module is loaded as part of executing a
+directory, zipfile or other :data:`sys.path` entry.
In :ref:`the remaining cases <using-on-interface-options>`
-``__main__.__spec__`` is set to ``None``:
+``__main__.__spec__`` is set to ``None``, as the code used to populate the
+:mod:`__main__` does not correspond directly with an importable module:
- interactive prompt
- -c switch
- running from stdin
- running directly from a source or bytecode file
+Note that ``__main__.__spec__`` is always ``None`` in the last case,
+*even if* the file could technically be imported directly as a module
+instead. Use the :option:`-m` switch if valid module metadata is desired
+in :mod:`__main__`.
+
+Note also that even when ``__main__`` corresponds with an importable module
+and ``__main__.__spec__`` is set accordingly, they're still considered
+*distinct* modules. This is due to the fact that blocks guarded by
+``if __name__ == "__main__":`` checks only execute when the module is used
+to populate the ``__main__`` namespace, and not during normal import.
+
Open issues
===========
--
Repository URL: http://hg.python.org/cpython
More information about the Python-checkins
mailing list