diff options
author | Benjamin Peterson <benjamin@python.org> | 2012-04-18 14:55:43 (GMT) |
---|---|---|
committer | Benjamin Peterson <benjamin@python.org> | 2012-04-18 14:55:43 (GMT) |
commit | d76bc7abac37ac345878ed2db7e264f59fc79985 (patch) | |
tree | 0c933be1c1ebc649ba9279935cc75c13b05346fd /Lib/importlib/_bootstrap.py | |
parent | da20cd2b6bf40d712f6296b9e21ff099b22aab71 (diff) | |
download | cpython-d76bc7abac37ac345878ed2db7e264f59fc79985.zip cpython-d76bc7abac37ac345878ed2db7e264f59fc79985.tar.gz cpython-d76bc7abac37ac345878ed2db7e264f59fc79985.tar.bz2 |
rollback 005fd1fe31ab (see #14609 and #14582)
Being able to overload a sys.module entry during import of a module was broken
by this changeset.
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r-- | Lib/importlib/_bootstrap.py | 16 |
1 files changed, 6 insertions, 10 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py index 415c488..142461a 100644 --- a/Lib/importlib/_bootstrap.py +++ b/Lib/importlib/_bootstrap.py @@ -984,12 +984,12 @@ def _find_and_load(name, import_): loader = _find_module(name, path) if loader is None: raise ImportError(_ERR_MSG.format(name), name=name) - elif name in sys.modules: - # The parent module already imported this module. - module = sys.modules[name] - else: - module = loader.load_module(name) + elif name not in sys.modules: + # The parent import may have already imported this module. + loader.load_module(name) verbose_message('import {!r} # {!r}', name, loader) + # Backwards-compatibility; be nicer to skip the dict lookup. + module = sys.modules[name] if parent: # Set the module as an attribute on its parent. parent_module = sys.modules[parent] @@ -1088,11 +1088,7 @@ def __import__(name, globals={}, locals={}, fromlist=[], level=0): # Return up to the first dot in 'name'. This is complicated by the fact # that 'name' may be relative. if level == 0: - index = name.find('.') - if index == -1: - return module - else: - return sys.modules[name[:index]] + return sys.modules[name.partition('.')[0]] elif not name: return module else: |