cpython: 4972475ae2e7 (original) (raw)

Mercurial > cpython

changeset 90016:4972475ae2e7 3.4

Issue #19697: Document cases where __main__.__spec__ is None. [#19697]

Eric Snow ericsnowcurrently@gmail.com
date Fri, 28 Mar 2014 18:10:33 -0600
parents deb71529aad1
children ae5169297eb9 3036985cf895
files Doc/reference/import.rst Misc/NEWS
diffstat 2 files changed, 43 insertions(+), 1 deletions(-)[+] [-] Doc/reference/import.rst 42 Misc/NEWS 2

line wrap: on

line diff

--- a/Doc/reference/import.rst +++ b/Doc/reference/import.rst @@ -519,7 +519,10 @@ the module. The __spec__ attribute must be set to the module spec that was used when importing the module. This is used primarily for

@@ -829,6 +832,37 @@ it is sufficient to raise :exc:ImportEr[](#l1.15) while raising an exception terminates it immediately.[](#l1.16) [](#l1.17) [](#l1.18) +Special considerations for __main__[](#l1.19) +===================================[](#l1.20) +[](#l1.21) +The :mod:main module is a special case relative to Python's import[](#l1.22) +system. As noted :ref:elsewhere , the ``__main__`` module[](#l1.23) +is directly initialized at interpreter startup, much like :mod:sys and[](#l1.24) +:mod:builtins. However, unlike those two, it doesn't strictly[](#l1.25) +qualify as a built-in module. This is because the manner in which[](#l1.26) +``__main__`` is initialized depends on the flags and other options with[](#l1.27) +which the interpreter is invoked.[](#l1.28) +[](#l1.29) +.. _main_spec:[](#l1.30) +[](#l1.31) +__main__.__spec__[](#l1.32) +-----------------[](#l1.33) +[](#l1.34) +Depending on how :mod:main is initialized, ``__main__.__spec__``[](#l1.35) +gets set appropriately or to ``None``.[](#l1.36) +[](#l1.37) +When Python is started with the :option:-m option, ``__spec__`` is set[](#l1.38) +to the module spec of the corresponding module.[](#l1.39) +[](#l1.40) +In :ref:the remaining cases [](#l1.41) +``__main__.__spec__`` is set to ``None``:[](#l1.42) +[](#l1.43) +- interactive prompt[](#l1.44) +- -c switch[](#l1.45) +- running from stdin[](#l1.46) +- running directly from a source or bytecode file[](#l1.47) +[](#l1.48) +[](#l1.49) Open issues[](#l1.50) ===========[](#l1.51) [](#l1.52) @@ -841,6 +875,12 @@ related entries in the data model refere[](#l1.53) XXX runpy, pkgutil, et al in the library manual should all get "See Also"[](#l1.54) links at the top pointing to the new import system section.[](#l1.55) [](#l1.56) +XXX Add more explanation regarding the different ways in which[](#l1.57) +``__main__`` is initialized?[](#l1.58) +[](#l1.59) +XXX Add more info on ``__main__`` quirks/pitfalls (i.e. copy from[](#l1.60) +:pep:395`). + References ==========

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -115,6 +115,8 @@ Documentation required reference material for tool developers that isn't recorded anywhere else. +- Issue #19697: Document cases where main.spec is None. + Tests -----