summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorBrett Cannon <brett@python.org>2013-07-04 21:51:50 (GMT)
committerBrett Cannon <brett@python.org>2013-07-04 21:51:50 (GMT)
commit679ecb565be82ade822411dcfb1b954a60954890 (patch)
tree2e06376ed152ad58a882c57566a5d11549803644 /Lib/importlib
parent82da8886cc3d8166ab8ef5a257cb04a32ddb1720 (diff)
downloadcpython-679ecb565be82ade822411dcfb1b954a60954890.zip
cpython-679ecb565be82ade822411dcfb1b954a60954890.tar.gz
cpython-679ecb565be82ade822411dcfb1b954a60954890.tar.bz2
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 09d8f0e..6607866 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