summaryrefslogtreecommitdiff
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-07-04 17:51:50 -0400
committerBrett Cannon <brett@python.org>2013-07-04 17:51:50 -0400
commitd5e4e1699da17182503b77eb27bf6cee3c46bb7f (patch)
treedfab4647b94ef9d1260d072a9c5de427a958a035 /Lib/importlib
parentaf5e4f4219618da2bfcb02b52ac7c7ac54b7542a (diff)
downloadcpython-d5e4e1699da17182503b77eb27bf6cee3c46bb7f.tar.gz
Issue #15767: back out 8a0ed9f63c6e, finishing the removal of
ModuleNotFoundError.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py15
1 files changed, 11 insertions, 4 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 09d8f0e9bc..66078665fc 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -1556,7 +1556,11 @@ def _find_and_load_unlocked(name, import_):
raise ImportError(msg, name=name)
loader = _find_module(name, path)
if loader is None:
- raise ModuleNotFoundError(_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)
@@ -1642,12 +1646,15 @@ def _handle_fromlist(module, fromlist, import_):
from_name = '{}.{}'.format(module.__name__, x)
try:
_call_with_frames_removed(import_, from_name)
- except ModuleNotFoundError as exc:
+ except ImportError as exc:
# Backwards-compatibility dictates we ignore failed
# imports triggered by fromlist for modules that don't
# exist.
- if exc.name == from_name:
- continue
+ # TODO(brett): In Python 3.4, have import raise
+ # ModuleNotFound and catch that.
+ if getattr(exc, '_not_found', False):
+ if exc.name == from_name:
+ continue
raise
return module