Commit c4464052 authored by Serhiy Storchaka's avatar Serhiy Storchaka

Issue #19720: Suppressed context for some exceptions in importlib.

parent b6e2556d
...@@ -73,7 +73,7 @@ def find_loader(name, path=None): ...@@ -73,7 +73,7 @@ def find_loader(name, path=None):
except KeyError: except KeyError:
pass pass
except AttributeError: except AttributeError:
raise ValueError('{}.__loader__ is not set'.format(name)) raise ValueError('{}.__loader__ is not set'.format(name)) from None
spec = _bootstrap._find_spec(name, path) spec = _bootstrap._find_spec(name, path)
# We won't worry about malformed specs (missing attributes). # We won't worry about malformed specs (missing attributes).
...@@ -138,7 +138,8 @@ def reload(module): ...@@ -138,7 +138,8 @@ def reload(module):
parent = sys.modules[parent_name] parent = sys.modules[parent_name]
except KeyError: except KeyError:
msg = "parent {!r} not in sys.modules" msg = "parent {!r} not in sys.modules"
raise ImportError(msg.format(parent_name), name=parent_name) raise ImportError(msg.format(parent_name),
name=parent_name) from None
else: else:
pkgpath = parent.__path__ pkgpath = parent.__path__
else: else:
......
...@@ -2172,7 +2172,7 @@ def _find_and_load_unlocked(name, import_): ...@@ -2172,7 +2172,7 @@ def _find_and_load_unlocked(name, import_):
path = parent_module.__path__ path = parent_module.__path__
except AttributeError: except AttributeError:
msg = (_ERR_MSG + '; {!r} is not a package').format(name, parent) msg = (_ERR_MSG + '; {!r} is not a package').format(name, parent)
raise ImportError(msg, name=name) raise ImportError(msg, name=name) from None
spec = _find_spec(name, path) spec = _find_spec(name, path)
if spec is None: if spec is None:
raise ImportError(_ERR_MSG.format(name), name=name) raise ImportError(_ERR_MSG.format(name), name=name)
......
...@@ -56,7 +56,7 @@ def _find_spec_from_path(name, path=None): ...@@ -56,7 +56,7 @@ def _find_spec_from_path(name, path=None):
try: try:
spec = module.__spec__ spec = module.__spec__
except AttributeError: except AttributeError:
raise ValueError('{}.__spec__ is not set'.format(name)) raise ValueError('{}.__spec__ is not set'.format(name)) from None
else: else:
if spec is None: if spec is None:
raise ValueError('{}.__spec__ is None'.format(name)) raise ValueError('{}.__spec__ is None'.format(name))
...@@ -96,7 +96,7 @@ def find_spec(name, package=None): ...@@ -96,7 +96,7 @@ def find_spec(name, package=None):
try: try:
spec = module.__spec__ spec = module.__spec__
except AttributeError: except AttributeError:
raise ValueError('{}.__spec__ is not set'.format(name)) raise ValueError('{}.__spec__ is not set'.format(name)) from None
else: else:
if spec is None: if spec is None:
raise ValueError('{}.__spec__ is None'.format(name)) raise ValueError('{}.__spec__ is None'.format(name))
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment