summaryrefslogtreecommitdiffstats
path: root/Lib/importlib/_bootstrap.py
diff options
context:
space:
mode:
Diffstat (limited to 'Lib/importlib/_bootstrap.py')
-rw-r--r--Lib/importlib/_bootstrap.py18
1 files changed, 14 insertions, 4 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 861900c..171adc5 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1513,7 +1513,11 @@ def _find_and_load_unlocked(name, import_):
raise ImportError(msg, name=name)
loader = _find_module(name, path)
if loader is None:
- raise ImportError(_ERR_MSG.format(name), name=name)
+ exc = ImportError(_ERR_MSG.format(name), name=name)
+ # TODO(brett): switch to a proper ModuleNotFound exception in Python
+ # 3.4.
+ exc._not_found = True
+ raise exc
elif name not in sys.modules:
# The parent import may have already imported this module.
loader.load_module(name)
@@ -1599,10 +1603,16 @@ def _handle_fromlist(module, fromlist, import_):
try:
_call_with_frames_removed(import_,
'{}.{}'.format(module.__name__, x))
- except ImportError:
+ except ImportError as exc:
# Backwards-compatibility dictates we ignore failed
- # imports triggered by fromlist.
- pass
+ # imports triggered by fromlist for modules that don't
+ # exist.
+ # TODO(brett): In Python 3.4, have import raise
+ # ModuleNotFound and catch that.
+ if hasattr(exc, '_not_found') and exc._not_found:
+ pass
+ else:
+ raise
return module