[pypy-commit] pypy py3k: use the official way to check whether an object is a valid traceback, and add a test

antocuni noreply at buildbot.pypy.org
Wed Feb 15 12:34:19 CET 2012


Author: Antonio Cuni <anto.cuni at gmail.com>
Branch: py3k
Changeset: r52503:5cee50641566
Date: 2012-02-15 11:24 +0100
http://bitbucket.org/pypy/pypy/changeset/5cee50641566/

Log:	use the official way to check whether an object is a valid
	traceback, and add a test

diff --git a/pypy/module/exceptions/interp_exceptions.py b/pypy/module/exceptions/interp_exceptions.py
--- a/pypy/module/exceptions/interp_exceptions.py
+++ b/pypy/module/exceptions/interp_exceptions.py
@@ -78,7 +78,7 @@
     descr_set_dict, descr_del_dict)
 from pypy.interpreter.gateway import interp2app
 from pypy.interpreter.error import OperationError
-from pypy.interpreter.pytraceback import PyTraceback
+from pypy.interpreter.pytraceback import check_traceback
 from pypy.rlib import rwin32
 
 def readwrite_attrproperty_w(name, cls):
@@ -175,9 +175,8 @@
         return self.w_traceback
 
     def descr_settraceback(self, space, w_newtraceback):
-        # Check argument
-        space.interp_w(PyTraceback, w_newtraceback, can_be_None=True)
-        self.w_traceback = w_newtraceback
+        msg = '__traceback__ must be a traceback or None'
+        self.w_traceback = check_traceback(space, w_newtraceback, msg)
 
     def descr_getitem(self, space, w_index):
         return space.getitem(space.newtuple(self.args_w), w_index)
diff --git a/pypy/module/exceptions/test/test_exc.py b/pypy/module/exceptions/test/test_exc.py
--- a/pypy/module/exceptions/test/test_exc.py
+++ b/pypy/module/exceptions/test/test_exc.py
@@ -271,3 +271,7 @@
             tb = sys.exc_info()[2]
             assert e.with_traceback(tb) is e
             assert e.__traceback__ is tb
+
+    def test_set_traceback(self):
+        e = Exception()
+        raises(TypeError, "e.__traceback__ = 42")


More information about the pypy-commit mailing list