[pypy-svn] r57435 - in pypy/branch/2.5-features/pypy/interpreter: . test
bgola at codespeak.net
bgola at codespeak.net
Mon Aug 18 18:13:52 CEST 2008
Author: bgola
Date: Mon Aug 18 18:13:50 2008
New Revision: 57435
Modified:
pypy/branch/2.5-features/pypy/interpreter/generator.py
pypy/branch/2.5-features/pypy/interpreter/pyopcode.py
pypy/branch/2.5-features/pypy/interpreter/pytraceback.py
pypy/branch/2.5-features/pypy/interpreter/test/test_generator.py
Log:
fix: throw() method now unwraps the w_tb value before testing and raising OpError
Modified: pypy/branch/2.5-features/pypy/interpreter/generator.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/generator.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/generator.py Mon Aug 18 18:13:50 2008
@@ -72,25 +72,22 @@
def throw(self, w_type, w_val, w_tb):
- from pypy.interpreter.typedef import PyTraceback
+ from pypy.interpreter.pytraceback import check_traceback
space = self.space
+
+ msg = "throw() third argument must be a traceback object"
+ tb = check_traceback(space, w_tb, msg)
- if w_tb is not None:
- if not space.is_true(space.isinstance(w_tb,
- space.gettypeobject(PyTraceback.typedef))):
- msg = "throw() third argument must be a traceback object"
- raise OperationError(space.w_TypeError, space.wrap(msg))
-
if space.is_true(space.abstract_isclass(w_type)) and \
space.is_true(space.issubtype(w_type, space.w_BaseException)):
- exception = OperationError(w_type, w_val, w_tb)
+ exception = OperationError(w_type, w_val, tb)
elif space.is_true(space.isinstance(w_type, space.w_BaseException)):
if not space.is_w(w_val, space.w_None):
msg = "instance exception may not have a separate value"
raise OperationError(space.w_TypeError, space.wrap(msg))
else:
- exception = OperationError(w_type.getclass(space), w_val, w_tb)
+ exception = OperationError(w_type.getclass(space), w_val, tb)
else:
if not space.is_true(space.isinstance(w_type, space.w_str)):
@@ -98,7 +95,7 @@
w_type.typedef.name)
raise OperationError(space.w_TypeError, space.wrap(msg))
else:
- exception = OperationError(w_type, w_val, w_tb)
+ exception = OperationError(w_type, w_val, tb)
ec = space.getexecutioncontext()
next_instr = self.frame.handle_operation_error(ec, exception)
Modified: pypy/branch/2.5-features/pypy/interpreter/pyopcode.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/pyopcode.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/pyopcode.py Mon Aug 18 18:13:50 2008
@@ -522,11 +522,9 @@
# common case
raise operror
else:
- tb = space.interpclass_w(w_traceback)
- if tb is None or not space.is_true(space.isinstance(tb,
- space.gettypeobject(pytraceback.PyTraceback.typedef))):
- raise OperationError(space.w_TypeError,
- space.wrap("raise: arg 3 must be a traceback or None"))
+ from pypy.interpreter.pytraceback import check_traceback
+ msg = "raise: arg 3 must be a traceback or None"
+ tb = check_traceback(space, w_traceback, msg)
operror.application_traceback = tb
# re-raise, no new traceback obj will be attached
f.last_exception = operror
Modified: pypy/branch/2.5-features/pypy/interpreter/pytraceback.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/pytraceback.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/pytraceback.py Mon Aug 18 18:13:50 2008
@@ -1,4 +1,5 @@
from pypy.interpreter import baseobjspace
+from pypy.interpreter.error import OperationError
class PyTraceback(baseobjspace.Wrappable):
@@ -62,3 +63,15 @@
break
line = line + ord(tab[i+1])
return line
+
+def check_traceback(space, w_tb, msg):
+ from pypy.interpreter.typedef import PyTraceback
+ if w_tb is not None:
+ tb = space.interpclass_w(w_tb)
+ if tb is None or not space.is_true(space.isinstance(tb,
+ space.gettypeobject(PyTraceback.typedef))):
+ raise OperationError(space.w_TypeError, space.wrap(msg))
+ else:
+ tb = None
+ return tb
+
Modified: pypy/branch/2.5-features/pypy/interpreter/test/test_generator.py
==============================================================================
--- pypy/branch/2.5-features/pypy/interpreter/test/test_generator.py (original)
+++ pypy/branch/2.5-features/pypy/interpreter/test/test_generator.py Mon Aug 18 18:13:50 2008
@@ -58,7 +58,7 @@
assert g.throw(NameError("Error")) == 3
raises(StopIteration, g.next)
- def test_throw3(self):
+ def test_throw4(self):
def f():
try:
yield 1
@@ -71,7 +71,7 @@
assert g.throw(NameError("Error")) == 3
raises(StopIteration, g.next)
- def test_throw4(self):
+ def test_throw5(self):
def f():
try:
yield 1
More information about the Pypy-commit
mailing list