summaryrefslogtreecommitdiffstats
path: root/Lib/importlib
diff options
context:
space:
mode:
authorAntoine Pitrou <solipsis@pitrou.net>2012-07-08 10:01:27 (GMT)
committerAntoine Pitrou <solipsis@pitrou.net>2012-07-08 10:01:27 (GMT)
commitbc07a5c9136c316383550ef38299792ab07eb167 (patch)
tree25a59bde65b32cd0eb88c03aa217e2ff50fc62d1 /Lib/importlib
parent25bfb529bd08eff831a258e2dbd1fed70bfa40ae (diff)
downloadcpython-bc07a5c9136c316383550ef38299792ab07eb167.zip
cpython-bc07a5c9136c316383550ef38299792ab07eb167.tar.gz
cpython-bc07a5c9136c316383550ef38299792ab07eb167.tar.bz2
Issue #15110: Fix the tracebacks generated by "import xxx" to not show the importlib stack frames.
Diffstat (limited to 'Lib/importlib')
-rw-r--r--Lib/importlib/_bootstrap.py25
1 files changed, 22 insertions, 3 deletions
diff --git a/Lib/importlib/_bootstrap.py b/Lib/importlib/_bootstrap.py
index 97ab18d..0666168 100644
--- a/Lib/importlib/_bootstrap.py
+++ b/Lib/importlib/_bootstrap.py
@@ -541,7 +541,7 @@ class FrozenImporter:
"""Load a frozen module."""
is_reload = fullname in sys.modules
try:
- m = _imp.init_frozen(fullname)
+ m = cls._exec_module(fullname)
# Let our own module_repr() method produce a suitable repr.
del m.__file__
return m
@@ -568,6 +568,13 @@ class FrozenImporter:
"""Return if the frozen module is a package."""
return _imp.is_frozen_package(fullname)
+ @classmethod
+ def _exec_module(cls, fullname):
+ """Helper for load_module, allowing to isolate easily (when
+ looking at a traceback) whether an error comes from executing
+ an imported module's code."""
+ return _imp.init_frozen(fullname)
+
class _LoaderBasics:
@@ -644,9 +651,15 @@ class _LoaderBasics:
else:
module.__package__ = module.__package__.rpartition('.')[0]
module.__loader__ = self
- exec(code_object, module.__dict__)
+ self._exec_module(code_object, module.__dict__)
return module
+ def _exec_module(self, code_object, module_dict):
+ """Helper for _load_module, allowing to isolate easily (when
+ looking at a traceback) whether an error comes from executing
+ an imported module's code."""
+ exec(code_object, module_dict)
+
class SourceLoader(_LoaderBasics):
@@ -869,7 +882,7 @@ class ExtensionFileLoader:
"""Load an extension module."""
is_reload = fullname in sys.modules
try:
- module = _imp.load_dynamic(fullname, self.path)
+ module = self._exec_module(fullname, self.path)
_verbose_message('extension module loaded from {!r}', self.path)
return module
except:
@@ -889,6 +902,12 @@ class ExtensionFileLoader:
"""Return None as extension modules have no source code."""
return None
+ def _exec_module(self, fullname, path):
+ """Helper for load_module, allowing to isolate easily (when
+ looking at a traceback) whether an error comes from executing
+ an imported module's code."""
+ return _imp.load_dynamic(fullname, path)
+
class _NamespacePath:
"""Represents a namespace package's path. It uses the module name