summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorEric Snow <ericsnowcurrently@gmail.com>2016-09-07 23:56:15 (GMT)
committerEric Snow <ericsnowcurrently@gmail.com>2016-09-07 23:56:15 (GMT)
commit46f97b85a8ce9ae67b6e4bc32e94f7827df7bab7 (patch)
treee814eb2b2365001ddbc119372da70eed52f2aeb5 /Lib/importlib
parentc943265ba56e7ce7e2fe79fdecfc6670e10e5467 (diff)
downloadcpython-46f97b85a8ce9ae67b6e4bc32e94f7827df7bab7.zip
cpython-46f97b85a8ce9ae67b6e4bc32e94f7827df7bab7.tar.gz
cpython-46f97b85a8ce9ae67b6e4bc32e94f7827df7bab7.tar.bz2
Issue #15767: Use ModuleNotFoundError.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py14
1 files changed, 7 insertions, 7 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 2eeafe1..8cd0262 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -943,10 +943,10 @@ def _find_and_load_unlocked(name, import_):
path = parent_module.__path__
except AttributeError:
msg = (_ERR_MSG + '; {!r} is not a package').format(name, parent)
- raise ImportError(msg, name=name) from None
+ raise ModuleNotFoundError(msg, name=name) from None
spec = _find_spec(name, path)
if spec is None:
- raise ImportError(_ERR_MSG.format(name), name=name)
+ raise ModuleNotFoundError(_ERR_MSG.format(name), name=name)
else:
module = _load_unlocked(spec)
if parent:
@@ -982,10 +982,11 @@ def _gcd_import(name, package=None, level=0):
_imp.release_lock()
message = ('import of {} halted; '
'None in sys.modules'.format(name))
- raise ImportError(message, name=name)
+ raise ModuleNotFoundError(message, name=name)
_lock_unlock_module(name)
return module
+
def _handle_fromlist(module, fromlist, import_):
"""Figure out what __import__ should return.
@@ -1007,13 +1008,12 @@ def _handle_fromlist(module, fromlist, import_):
from_name = '{}.{}'.format(module.__name__, x)
try:
_call_with_frames_removed(import_, from_name)
- except ImportError as exc:
+ except ModuleNotFoundError as exc:
# Backwards-compatibility dictates we ignore failed
# imports triggered by fromlist for modules that don't
# exist.
- if str(exc).startswith(_ERR_MSG_PREFIX):
- if exc.name == from_name:
- continue
+ if exc.name == from_name:
+ continue
raise
return module