New submission from Sergei Lebedev:
According to the current import system documentation
> When calling ``__import__()`` as part of an import statement, the import
> system first checks the module global namespace for a function by that name.
> If it is not found, then the standard builtin ``__import__()`` is called.
However, one can easily verify this isn't (always) the case::
import sys
assert "glob" not in sys.modules
__import__ = print
import glob # Doesn't print anything.
I've traced the import statement from ``ceval.c`` to the frozen
``importlib._bootstrap`` and it seems the cause of the problem is in
``_find_and_load_unlocked``, which simply ignores the ``_import`` argument in
the case above::
def _find_and_load_unlocked(name, import_):
path = None
# ... parent processing ...
spec = _find_spec(name, path)
if spec is None:
raise ImportError(_ERR_MSG.format(name), name=name)
else:
# XXX import_ is not used.
module = _SpecMethods(spec)._load_unlocked()
# ... more parent processing ...
return module
I'm not sure if this is a bug in the documentation or implementation, so any
feedback is appreciated.
----------
assignee: docs@python
components: Documentation, Library (Lib)
messages: 253635
nosy: docs@python, superbobry
priority: normal
severity: normal
status: open
title: _find_and_load_unlocked doesn't always use __import__
versions: Python 3.4, Python 3.5
_______________________________________
Python tracker <[email protected]>
<http://bugs.python.org/issue25500>
_______________________________________
_______________________________________________
Python-bugs-list mailing list
Unsubscribe:
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com