mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
Issue #15110: Fix the tracebacks generated by "import xxx" to not show the importlib stack frames.
This commit is contained in:
parent
25bfb529bd
commit
bc07a5c913
5 changed files with 2737 additions and 2479 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue