]> granicus.if.org Git - python/commitdiff
Issue #19720: Suppressed context for some exceptions in importlib.
authorSerhiy Storchaka <storchaka@gmail.com>
Fri, 21 Nov 2014 18:33:57 +0000 (20:33 +0200)
committerSerhiy Storchaka <storchaka@gmail.com>
Fri, 21 Nov 2014 18:33:57 +0000 (20:33 +0200)
Lib/importlib/__init__.py
Lib/importlib/_bootstrap.py
Lib/importlib/util.py

index e0fe4665f4f18b026b2e732a2932e42beffd7c15..e99f50e0f167e7c41579c510584163a46409eda7 100644 (file)
@@ -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:
index fff9eacd0ca6a47cd318132256b06b84da7f83ce..64aea610160c1934078ab4fad750ddd0746df850 100644 (file)
@@ -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)
index 2424144b91f6d1c2ff6fe2d6804b05bba914d1ad..c42ef14c5d51a4150c42c2279160eea83b4f9510 100644 (file)
@@ -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))