Have importlib raise ImportError if None is found in sys.modules. This matches

current import semantics.
This commit is contained in:
Brett Cannon 2009-08-30 03:47:36 +00:00
parent ccd686a473
commit 4d75fc1ce9
3 changed files with 22 additions and 5 deletions

View file

@ -864,7 +864,12 @@ def _gcd_import(name, package=None, level=0):
name = package[:dot]
with _ImportLockContext():
try:
return sys.modules[name]
module = sys.modules[name]
if module is None:
message = ("import of {} halted; "
"None in sys.modules".format(name))
raise ImportError(message)
return module
except KeyError:
pass
parent = name.rpartition('.')[0]