mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15767: back out 8a0ed9f63c6e, finishing the removal of
ModuleNotFoundError.
This commit is contained in:
parent
82da8886cc
commit
679ecb565b
17 changed files with 412 additions and 427 deletions
|
@ -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
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue