summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorSerhiy Storchaka <storchaka@gmail.com>2014-11-21 20:33:57 +0200
committerSerhiy Storchaka <storchaka@gmail.com>2014-11-21 20:33:57 +0200
commit86634aeb7cdc39bfd2e81061878d50d25947a7e5 (patch)
treea5dc7885c73ebad2049b845aee65ded2c52bb0d8
parentb00734557c605a4f042e4d7b7e91f2e9c557a933 (diff)
downloadcpython-86634aeb7cdc39bfd2e81061878d50d25947a7e5.tar.gz
Issue #19720: Suppressed context for some exceptions in importlib.
-rw-r--r--Lib/importlib/__init__.py5
-rw-r--r--Lib/importlib/_bootstrap.py2
-rw-r--r--Lib/importlib/util.py4
3 files changed, 6 insertions, 5 deletions
diff --git a/Lib/importlib/__init__.py b/Lib/importlib/__init__.py
index e0fe4665f4..e99f50e0f1 100644
--- a/Lib/importlib/__init__.py
+++ b/Lib/importlib/__init__.py
@@ -73,7 +73,7 @@ def find_loader(name, path=None):
except KeyError:
pass
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)
# We won't worry about malformed specs (missing attributes).
@@ -138,7 +138,8 @@ def reload(module):
parent = sys.modules[parent_name]
except KeyError:
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:
pkgpath = parent.__path__
else:
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index fff9eacd0c..64aea61016 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -2172,7 +2172,7 @@ 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)
+ raise ImportError(msg, name=name) from None
spec = _find_spec(name, path)
if spec is None:
raise ImportError(_ERR_MSG.format(name), name=name)
diff --git a/Lib/importlib/util.py b/Lib/importlib/util.py
index 2424144b91..c42ef14c5d 100644
--- a/Lib/importlib/util.py
+++ b/Lib/importlib/util.py
@@ -56,7 +56,7 @@ def _find_spec_from_path(name, path=None):
try:
spec = module.__spec__
except AttributeError:
- raise ValueError('{}.__spec__ is not set'.format(name))
+ raise ValueError('{}.__spec__ is not set'.format(name)) from None
else:
if spec is None:
raise ValueError('{}.__spec__ is None'.format(name))
@@ -96,7 +96,7 @@ def find_spec(name, package=None):
try:
spec = module.__spec__
except AttributeError:
- raise ValueError('{}.__spec__ is not set'.format(name))
+ raise ValueError('{}.__spec__ is not set'.format(name)) from None
else:
if spec is None:
raise ValueError('{}.__spec__ is None'.format(name))