[pypy-commit] pypy translation-cleanup: Replace operr.normalize_exception() with space.exc_from_raise()
rlamy
noreply at buildbot.pypy.org
Sat Sep 22 15:59:16 CEST 2012
Author: Ronan Lamy <ronan.lamy at gmail.com>
Branch: translation-cleanup
Changeset: r57475:d1d1a2728e07
Date: 2012-09-22 05:23 +0100
http://bitbucket.org/pypy/pypy/changeset/d1d1a2728e07/
Log: Replace operr.normalize_exception() with space.exc_from_raise()
diff --git a/pypy/objspace/flow/flowcontext.py b/pypy/objspace/flow/flowcontext.py
--- a/pypy/objspace/flow/flowcontext.py
+++ b/pypy/objspace/flow/flowcontext.py
@@ -1,7 +1,7 @@
import collections
import sys
from pypy.tool.error import source_lines
-from pypy.interpreter.error import OperationError, operationerrfmt
+from pypy.interpreter.error import OperationError
from pypy.interpreter.pytraceback import PyTraceback
from pypy.interpreter import pyframe
from pypy.interpreter.nestedscope import Cell
@@ -44,42 +44,6 @@
def __str__(self):
return '[%s: %s]' % (self.w_type, self.w_value)
- def normalize_exception(self, space):
- """Normalize the OperationError. In other words, fix w_type and/or
- w_value to make sure that the __class__ of w_value is exactly w_type.
- """
- w_type = self.w_type
- w_value = self.w_value
- if space.exception_is_valid_obj_as_class_w(w_type):
- # this is for all cases of the form (Class, something)
- if space.is_w(w_value, space.w_None):
- # raise Type: we assume we have to instantiate Type
- w_value = space.call_function(w_type)
- w_type = space.type(w_value)
- else:
- w_valuetype = space.type(w_value)
- if space.exception_issubclass_w(w_valuetype, w_type):
- # raise Type, Instance: let etype be the exact type of value
- w_type = w_valuetype
- else:
- # raise Type, X: assume X is the constructor argument
- w_value = space.call_function(w_type, w_value)
- w_type = space.type(w_value)
-
- else:
- # the only case left here is (inst, None), from a 'raise inst'.
- w_inst = w_type
- w_instclass = space.type(w_inst)
- if not space.is_w(w_value, space.w_None):
- raise FSException(space.w_TypeError,
- space.wrap("instance exception may not "
- "have a separate value"))
- w_value = w_inst
- w_type = w_instclass
-
- self.w_type = w_type
- self.w_value = w_value
-
class ImplicitOperationError(FSException):
pass
@@ -542,8 +506,7 @@
w_value = self.popvalue()
if 1:
w_type = self.popvalue()
- operror = FSException(w_type, w_value)
- operror.normalize_exception(space)
+ operror = space.exc_from_raise(w_type, w_value)
raise operror
def IMPORT_NAME(self, nameindex, next_instr):
diff --git a/pypy/objspace/flow/objspace.py b/pypy/objspace/flow/objspace.py
--- a/pypy/objspace/flow/objspace.py
+++ b/pypy/objspace/flow/objspace.py
@@ -205,6 +205,38 @@
return True
return False
+ def exc_from_raise(self, w_type, w_value):
+ """
+ Create a wrapped exception from the arguments of a raise statement.
+
+ Returns an FSException object whose w_value is an instance of w_type.
+ """
+ if self.exception_is_valid_obj_as_class_w(w_type):
+ # this is for all cases of the form (Class, something)
+ if self.is_w(w_value, self.w_None):
+ # raise Type: we assume we have to instantiate Type
+ w_value = self.call_function(w_type)
+ w_type = self.type(w_value)
+ else:
+ w_valuetype = self.type(w_value)
+ if self.exception_issubclass_w(w_valuetype, w_type):
+ # raise Type, Instance: let etype be the exact type of value
+ w_type = w_valuetype
+ else:
+ # raise Type, X: assume X is the constructor argument
+ w_value = self.call_function(w_type, w_value)
+ w_type = self.type(w_value)
+ else:
+ # the only case left here is (inst, None), from a 'raise inst'.
+ w_inst = w_type
+ w_instclass = self.type(w_inst)
+ if not self.is_w(w_value, self.w_None):
+ raise FSException(self.w_TypeError, self.wrap(
+ "instance exception may not have a separate value"))
+ w_value = w_inst
+ w_type = w_instclass
+ return FSException(w_type, w_value)
+
def getconstclass(space, w_cls):
try:
ecls = space.unwrap(w_cls)
@@ -247,8 +279,7 @@
w_len = self.len(w_iterable)
w_correct = self.eq(w_len, self.wrap(expected_length))
if not self.is_true(w_correct):
- e = FSException(self.w_ValueError, self.w_None)
- e.normalize_exception(self)
+ e = self.exc_from_raise(self.w_ValueError, self.w_None)
raise e
return [self.do_operation('getitem', w_iterable, self.wrap(i))
for i in range(expected_length)]
More information about the pypy-commit
mailing list