mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Being able to overload a sys.module entry during import of a module was broken by this changeset.
This commit is contained in:
parent
da20cd2b6b
commit
d76bc7abac
5 changed files with 504 additions and 498 deletions
|
@ -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:
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue