Author: Antonio Cuni <[email protected]>
Branch: resource_warning
Changeset: r83578:005ca768df30
Date: 2016-04-07 22:18 +0200
http://bitbucket.org/pypy/pypy/changeset/005ca768df30/

Log:    don't show the 'anonymous' frame corresponding to the appexec when
        calling format_traceback

diff --git a/pypy/interpreter/baseobjspace.py b/pypy/interpreter/baseobjspace.py
--- a/pypy/interpreter/baseobjspace.py
+++ b/pypy/interpreter/baseobjspace.py
@@ -1760,8 +1760,11 @@
         try:
             return self.appexec([],
                          """():
-                import traceback
-                return "".join(traceback.format_stack())
+                import sys, traceback
+                # the "1" is because we don't want to show THIS code
+                # object in the traceback
+                f = sys._getframe(1)
+                return "".join(traceback.format_stack(f))
             """)
         finally:
             self.sys.track_resources = flag
diff --git a/pypy/interpreter/test/test_objspace.py 
b/pypy/interpreter/test/test_objspace.py
--- a/pypy/interpreter/test/test_objspace.py
+++ b/pypy/interpreter/test/test_objspace.py
@@ -427,3 +427,28 @@
         space.finish()
         # assert that we reach this point without getting interrupted
         # by the OperationError(NameError)
+
+    def test_format_traceback(self):
+        from pypy.tool.pytest.objspace import maketestobjspace
+        from pypy.interpreter.gateway import interp2app
+        #
+        def format_traceback(space):
+            return space.format_traceback()
+        #
+        space = maketestobjspace()
+        w_format_traceback = space.wrap(interp2app(format_traceback))
+        w_tb = space.appexec([w_format_traceback], """(format_traceback):
+            def foo():
+                return bar()
+            def bar():
+                return format_traceback()
+            return foo()
+        """)
+        tb = space.str_w(w_tb)
+        expected = '\n'.join([
+            '  File "?", line 6, in anonymous',  # this is the appexec code 
object
+            '  File "?", line 3, in foo',
+            '  File "?", line 5, in bar',
+            ''
+        ])
+        assert tb == expected
_______________________________________________
pypy-commit mailing list
[email protected]
https://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to