[pypy-svn] r69345 - in pypy/branch/faster-raise/pypy/module/exceptions: . test

arigo at codespeak.net arigo at codespeak.net
Tue Nov 17 14:33:14 CET 2009


Author: arigo
Date: Tue Nov 17 14:33:14 2009
New Revision: 69345

Modified:
   pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
Log:
Also fix UnicodeTranslateError, removing the last use of
readwrite_attrproperty.


Modified: pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py	Tue Nov 17 14:33:14 2009
@@ -78,13 +78,6 @@
 from pypy.interpreter.error import OperationError
 from pypy.rlib import rwin32
 
-def readwrite_attrproperty(name, cls, unwrapname):
-    def fget(space, obj):
-        return space.wrap(getattr(obj, name))
-    def fset(space, obj, w_val):
-        setattr(obj, name, getattr(space, unwrapname)(w_val))
-    return GetSetProperty(fget, fset, cls=cls)
-
 def readwrite_attrproperty_w(name, cls):
     def fget(space, obj):
         return getattr(obj, name)
@@ -244,16 +237,22 @@
 
 class W_UnicodeTranslateError(W_UnicodeError):
     """Unicode translation error."""
-    object = u''
-    start = 0
-    end = 0
-    reason = ''
+    object = None
+    start = None
+    end = None
+    reason = None
     
     def descr_init(self, space, w_object, w_start, w_end, w_reason):
-        self.object = space.unicode_w(w_object)
-        self.start = space.int_w(w_start)
-        self.end = space.int_w(w_end)
-        self.reason = space.str_w(w_reason)
+        # typechecking
+        space.unicode_w(w_object)
+        space.int_w(w_start)
+        space.int_w(w_end)
+        space.str_w(w_reason)
+        # assign attributes
+        self.w_object = w_object
+        self.w_start = w_start
+        self.w_end = w_end
+        self.w_reason = w_reason
         W_BaseException.descr_init(self, space, [w_object, w_start,
                                                  w_end, w_reason])
     descr_init.unwrap_spec = ['self', ObjSpace, W_Root, W_Root, W_Root,
@@ -280,10 +279,10 @@
     __new__ = _new(W_UnicodeTranslateError),
     __init__ = interp2app(W_UnicodeTranslateError.descr_init),
     __str__ = interp2app(W_UnicodeTranslateError.descr_str),
-    object = readwrite_attrproperty('object', W_UnicodeTranslateError, 'unicode_w'),
-    start  = readwrite_attrproperty('start', W_UnicodeTranslateError, 'int_w'),
-    end    = readwrite_attrproperty('end', W_UnicodeTranslateError, 'int_w'),
-    reason = readwrite_attrproperty('reason', W_UnicodeTranslateError, 'str_w'),
+    object = readwrite_attrproperty_w('w_object', W_UnicodeTranslateError),
+    start  = readwrite_attrproperty_w('w_start', W_UnicodeTranslateError),
+    end    = readwrite_attrproperty_w('w_end', W_UnicodeTranslateError),
+    reason = readwrite_attrproperty_w('w_reason', W_UnicodeTranslateError),
 )
 
 W_LookupError = _new_exception('LookupError', W_StandardError,

Modified: pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
==============================================================================
--- pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	(original)
+++ pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py	Tue Nov 17 14:33:14 2009
@@ -88,6 +88,8 @@
         ut.start = 4
         ut.object = u'012345'
         assert str(ut) == "can't translate character u'\\x34' in position 4: bah"
+        ut.object = []
+        assert ut.object == []
 
     def test_key_error(self):
         from exceptions import KeyError



More information about the Pypy-commit mailing list