[pypy-commit] pypy py3.3: In import errors, hide frames from importlib._bootstrap

amauryfa noreply at buildbot.pypy.org
Sun Dec 14 19:42:23 CET 2014


Author: Amaury Forgeot d'Arc <amauryfa at gmail.com>
Branch: py3.3
Changeset: r74924:97034435e2d0
Date: 2014-11-01 10:54 +0100
http://bitbucket.org/pypy/pypy/changeset/97034435e2d0/

Log:	In import errors, hide frames from importlib._bootstrap

diff --git a/pypy/interpreter/error.py b/pypy/interpreter/error.py
--- a/pypy/interpreter/error.py
+++ b/pypy/interpreter/error.py
@@ -320,6 +320,15 @@
         """
         self._application_traceback = traceback
 
+    def remove_traceback_module_frames(self, module_name):
+        from pypy.interpreter.pytraceback import PyTraceback
+        tb = self._application_traceback
+        while tb is not None and isinstance(tb, PyTraceback):
+            if tb.frame.pycode.co_filename != module_name:
+                break
+            tb = tb.next
+        self._application_traceback = tb
+
     def record_context(self, space, frame):
         """Record a __context__ for this exception from the current
         frame if one exists.
diff --git a/pypy/module/_frozen_importlib/__init__.py b/pypy/module/_frozen_importlib/__init__.py
--- a/pypy/module/_frozen_importlib/__init__.py
+++ b/pypy/module/_frozen_importlib/__init__.py
@@ -1,6 +1,7 @@
 import os
 from pypy.interpreter.mixedmodule import MixedModule
 from pypy.module.sys import initpath
+from pypy.module._frozen_importlib import interp_import
 
 lib_python = os.path.join(os.path.dirname(__file__),
                           '..', '..', '..', 'lib-python', '3')
@@ -29,11 +30,12 @@
                       space.wrap(space.builtin))
         code_w.exec_code(space, self.w_dict, self.w_dict)
 
+        self.w_import = space.wrap(interp_import.import_with_frames_removed)
+
     def startup(self, space):
         """Copy our __import__ to builtins."""
         w_install = self.getdictvalue(space, '_install')
         space.call_function(w_install,
                             space.getbuiltinmodule('sys'),
                             space.getbuiltinmodule('_imp'))
-        self.space.builtin.setdictvalue(space, '__import__',
-                                        self.getdictvalue(space, '__import__'))
+        self.space.builtin.setdictvalue(space, '__import__', self.w_import)
diff --git a/pypy/module/_frozen_importlib/interp_import.py b/pypy/module/_frozen_importlib/interp_import.py
new file mode 100644
--- /dev/null
+++ b/pypy/module/_frozen_importlib/interp_import.py
@@ -0,0 +1,12 @@
+from pypy.interpreter.gateway import interp2app
+from pypy.interpreter.error import OperationError
+
+ at interp2app
+def import_with_frames_removed(space, __args__):
+    try:
+        return space.call_args(
+            space.getbuiltinmodule('_frozen_importlib').getdictvalue(
+                space, '__import__'), __args__)
+    except OperationError as e:
+        e.remove_traceback_module_frames('<frozen importlib._bootstrap>')
+        raise


More information about the pypy-commit mailing list