This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

Author superbobry
Recipients docs@python, superbobry
Date 2015-10-28.21:34:44
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1446068084.58.0.390651859443.issue25500@psf.upfronthosting.co.za>
In-reply-to
Content
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.
History
Date User Action Args
2015-10-28 21:34:44superbobrysetrecipients: + superbobry, docs@python
2015-10-28 21:34:44superbobrysetmessageid: <1446068084.58.0.390651859443.issue25500@psf.upfronthosting.co.za>
2015-10-28 21:34:44superbobrylinkissue25500 messages
2015-10-28 21:34:44superbobrycreate