Message253635
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. |
|
Date |
User |
Action |
Args |
2015-10-28 21:34:44 | superbobry | set | recipients:
+ superbobry, docs@python |
2015-10-28 21:34:44 | superbobry | set | messageid: <1446068084.58.0.390651859443.issue25500@psf.upfronthosting.co.za> |
2015-10-28 21:34:44 | superbobry | link | issue25500 messages |
2015-10-28 21:34:44 | superbobry | create | |
|