[New-bugs-announce] [issue24081] Obsolete caveat in reload() docs

Petr Viktorin report at bugs.python.org
Thu Apr 30 16:12:34 CEST 2015


New submission from Petr Viktorin:

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.

----------
assignee: docs at python
components: Documentation
files: 0001-Remove-obsolete-caveat-from-reload-docs.patch
keywords: patch
messages: 242270
nosy: docs at python, encukou
priority: normal
severity: normal
status: open
title: Obsolete caveat in reload() docs
versions: Python 2.7, Python 3.4
Added file: http://bugs.python.org/file39235/0001-Remove-obsolete-caveat-from-reload-docs.patch

_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue24081>
_______________________________________


More information about the New-bugs-announce mailing list