Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit c446405

Browse files
Issue #19720: Suppressed context for some exceptions in importlib.
1 parent b6e2556 commit c446405

3 files changed

Lines changed: 6 additions & 5 deletions

File tree

Lib/importlib/__init__.py

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -73,7 +73,7 @@ def find_loader(name, path=None):
7373
except KeyError:
7474
pass
7575
except AttributeError:
76-
raise ValueError('{}.__loader__ is not set'.format(name))
76+
raise ValueError('{}.__loader__ is not set'.format(name)) from None
7777

7878
spec = _bootstrap._find_spec(name, path)
7979
# We won't worry about malformed specs (missing attributes).
@@ -138,7 +138,8 @@ def reload(module):
138138
parent = sys.modules[parent_name]
139139
except KeyError:
140140
msg = "parent {!r} not in sys.modules"
141-
raise ImportError(msg.format(parent_name), name=parent_name)
141+
raise ImportError(msg.format(parent_name),
142+
name=parent_name) from None
142143
else:
143144
pkgpath = parent.__path__
144145
else:

Lib/importlib/_bootstrap.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2172,7 +2172,7 @@ def _find_and_load_unlocked(name, import_):
21722172
path = parent_module.__path__
21732173
except AttributeError:
21742174
msg = (_ERR_MSG + '; {!r} is not a package').format(name, parent)
2175-
raise ImportError(msg, name=name)
2175+
raise ImportError(msg, name=name) from None
21762176
spec = _find_spec(name, path)
21772177
if spec is None:
21782178
raise ImportError(_ERR_MSG.format(name), name=name)

Lib/importlib/util.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -56,7 +56,7 @@ def _find_spec_from_path(name, path=None):
5656
try:
5757
spec = module.__spec__
5858
except AttributeError:
59-
raise ValueError('{}.__spec__ is not set'.format(name))
59+
raise ValueError('{}.__spec__ is not set'.format(name)) from None
6060
else:
6161
if spec is None:
6262
raise ValueError('{}.__spec__ is None'.format(name))
@@ -96,7 +96,7 @@ def find_spec(name, package=None):
9696
try:
9797
spec = module.__spec__
9898
except AttributeError:
99-
raise ValueError('{}.__spec__ is not set'.format(name))
99+
raise ValueError('{}.__spec__ is not set'.format(name)) from None
100100
else:
101101
if spec is None:
102102
raise ValueError('{}.__spec__ is None'.format(name))

0 commit comments

Comments
 (0)