Mercurial > cpython-lru_cache-weakref
diff Lib/importlib/_bootstrap.py @ 76390:db5e3431ee4c
rollback 005fd1fe31ab (see #14609 and #14582)
Being able to overload a sys.module entry during import of a module was broken
by this changeset.
| author | Benjamin Peterson <benjamin@python.org> |
|---|---|
| date | Wed, 18 Apr 2012 10:55:43 -0400 |
| parents | c1399cf7bd6a |
| children | 052732bd3c10 |
line wrap: on
line diff
--- a/Lib/importlib/_bootstrap.py Wed Apr 18 10:48:00 2012 -0400 +++ b/Lib/importlib/_bootstrap.py Wed Apr 18 10:55:43 2012 -0400 @@ -984,12 +984,12 @@ 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 @@ # 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:
