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

fijal at codespeak.net fijal at codespeak.net
Tue Nov 17 08:51:17 CET 2009


Author: fijal
Date: Tue Nov 17 08:51:16 2009
New Revision: 69329

Modified:
   pypy/branch/faster-raise/pypy/module/exceptions/interp_exceptions.py
   pypy/branch/faster-raise/pypy/module/exceptions/test/test_exc.py
Log:
A test and a fix, hopefully last


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 08:51:16 2009
@@ -331,6 +331,18 @@
             self.args_w = [args_w[0], args_w[1]]
     descr_init.unwrap_spec = ['self', ObjSpace, 'args_w']
 
+    # since we rebind args_w, we need special reduce, grump
+    def descr_reduce(self, space):
+        if not space.is_w(self.w_filename, space.w_None):
+            lst = [self.getclass(space), space.newtuple(
+                self.args_w + [self.w_filename])]
+        else:
+            lst = [self.getclass(space), space.newtuple(self.args_w)]
+        if self.w_dict is not None and space.is_true(self.w_dict):
+            lst = lst + [self.w_dict]
+        return space.newtuple(lst)
+    descr_reduce.unwrap_spec = ['self', ObjSpace]
+
     def descr_str(self, space):
         if (not space.is_w(self.w_errno, space.w_None) and
             not space.is_w(self.w_strerror, space.w_None)):
@@ -351,6 +363,7 @@
     __doc__ = W_EnvironmentError.__doc__,
     __module__ = 'exceptions',
     __new__ = _new(W_EnvironmentError),
+    __reduce__ = interp2app(W_EnvironmentError.descr_reduce),
     __init__ = interp2app(W_EnvironmentError.descr_init),
     __str__ = interp2app(W_EnvironmentError.descr_str),
     errno    = readwrite_attrproperty_w('w_errno',    W_EnvironmentError),

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 08:51:16 2009
@@ -198,12 +198,14 @@
                 assert e.__module__ == 'exceptions', e
 
     def test_reduce(self):
-        from exceptions import LookupError
+        from exceptions import LookupError, EnvironmentError
 
         le = LookupError(1, 2, "a")
         assert le.__reduce__() == (LookupError, (1, 2, "a"))
         le.xyz = (1, 2)
         assert le.__reduce__() == (LookupError, (1, 2, "a"), {"xyz": (1, 2)})
+        ee = EnvironmentError(1, 2, "a")
+        assert ee.__reduce__() == (EnvironmentError, (1, 2, "a"))
 
     def test_setstate(self):
         from exceptions import FutureWarning
@@ -214,3 +216,4 @@
         fw.__setstate__({'z': 1})
         assert fw.z == 1
         assert fw.xyz == (1, 2)
+



More information about the Pypy-commit mailing list