Message242270
imp.reload() and importlib.reload() docs state::
If a module is syntactically correct but its initialization fails, the first
:keyword:`import` statement for it does not bind its name locally, but does
store a (partially initialized) module object in ``sys.modules``. To reload
the module you must first :keyword:`import` it again (this will bind the name
to the partially initialized module object) before you can :func:`reload` it.
If I reading that correctly, "initialization" refers to executing the module, so for module containing just::
uninitialized_variable
the following::
>>> import sys
>>> import x
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/tmp/x.py", line 1, in <module>
uninitialized_variable
NameError: name 'uninitialized_variable' is not defined
should leave me with a initialized module in sys.modules['x']. However, this is not what happens, in either Python 3.4 or 2.7::
>>> sys.modules['x']
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
KeyError: 'x'
Here's a patch to remove the caveat in Python 3 docs.
If I missed something, and "initialization" refers to something else, it should be clarified. |
|
Date |
User |
Action |
Args |
2015-04-30 14:12:35 | petr.viktorin | set | recipients:
+ petr.viktorin, docs@python |
2015-04-30 14:12:34 | petr.viktorin | set | messageid: <1430403154.98.0.829139703368.issue24081@psf.upfronthosting.co.za> |
2015-04-30 14:12:34 | petr.viktorin | link | issue24081 messages |
2015-04-30 14:12:34 | petr.viktorin | create | |
|