[pypy-svn] r5119 - in pypy/trunk/src/pypy: interpreter/test objspace/std

arigo at codespeak.net arigo at codespeak.net
Wed Jun 16 17:28:43 CEST 2004


Author: arigo
Date: Wed Jun 16 17:28:43 2004
New Revision: 5119

Modified:
   pypy/trunk/src/pypy/interpreter/test/test_class.py
   pypy/trunk/src/pypy/objspace/std/floatobject.py
   pypy/trunk/src/pypy/objspace/std/intobject.py
   pypy/trunk/src/pypy/objspace/std/longobject.py
   pypy/trunk/src/pypy/objspace/std/objspace.py
Log:
+ fixed signature of space.newfloat()
+ long and float subclasses had the same problem as int subclasses
+ added missing long.__eq__()



Modified: pypy/trunk/src/pypy/interpreter/test/test_class.py
==============================================================================
--- pypy/trunk/src/pypy/interpreter/test/test_class.py	(original)
+++ pypy/trunk/src/pypy/interpreter/test/test_class.py	Wed Jun 16 17:28:43 2004
@@ -95,5 +95,23 @@
         self.assertEquals(type(int(x)), int)
         self.assertEquals(int(x), 5)
 
+    def test_long_subclass(self):
+        class R(long):
+            pass
+        x = R(5L)
+        self.assertEquals(type(x), R)
+        self.assertEquals(x, 5L)
+        self.assertEquals(type(long(x)), long)
+        self.assertEquals(long(x), 5L)
+
+    def test_float_subclass(self):
+        class R(float):
+            pass
+        x = R(5.5)
+        self.assertEquals(type(x), R)
+        self.assertEquals(x, 5.5)
+        self.assertEquals(type(float(x)), float)
+        self.assertEquals(float(x), 5.5)
+
 if __name__ == '__main__':
     testit.main()

Modified: pypy/trunk/src/pypy/objspace/std/floatobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/floatobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/floatobject.py	Wed Jun 16 17:28:43 2004
@@ -30,8 +30,14 @@
 delegate__Int.priority = PRIORITY_CHANGE_TYPE
 
 
-def float__Float(space, w_value):
-    return w_value
+# float__Float is supposed to do nothing, unless it has
+# a derived float object, where it should return
+# an exact one.
+def float__Float(space, w_float1):
+    if space.is_true(space.is_(space.type(w_float1), space.w_float)):
+        return w_float1
+    a = w_float1.floatval
+    return W_FloatObject(space, a)
 
 def int__Float(space, w_value):
     return space.newint(int(w_value.floatval))
@@ -231,10 +237,7 @@
     return W_FloatObject(space, -w_float1.floatval)
 
 def pos__Float(space, w_float):
-    if w_float.__class__ == W_FloatObject:
-        return w_float
-    else:
-        return W_FloatObject(space, w_float.floatval)
+    return float__Float(space, w_float)
 
 def abs__Float(space, w_float):
     return W_FloatObject(space, abs(w_float.floatval))

Modified: pypy/trunk/src/pypy/objspace/std/intobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/intobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/intobject.py	Wed Jun 16 17:28:43 2004
@@ -175,9 +175,9 @@
         raise OperationError(space.w_ZeroDivisionError,
                              space.wrap("integer division by zero"))
     except OverflowError:
-        return space.div(space.newfloat(x), w_int2)
+        return space.div(space.newfloat(float(x)), w_int2)
     if t != 0:   # gives a float
-        return space.div(space.newfloat(x), w_int2)
+        return space.div(space.newfloat(float(x)), w_int2)
     return W_IntObject(space, z)
 
 def mod__Int_Int(space, w_int1, w_int2):

Modified: pypy/trunk/src/pypy/objspace/std/longobject.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/longobject.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/longobject.py	Wed Jun 16 17:28:43 2004
@@ -39,8 +39,14 @@
 delegate__Long.can_fail = True
 
 
-def long__Long(space, w_value):
-    return w_value
+# long__Long is supposed to do nothing, unless it has
+# a derived long object, where it should return
+# an exact one.
+def long__Long(space, w_long1):
+    if space.is_true(space.is_(space.type(w_long1), space.w_long)):
+        return w_long1
+    a = w_long1.longval
+    return W_LongObject(space, a)
 
 def long__Int(space, w_intobj):
     return W_LongObject(space, long(w_intobj.intval))
@@ -66,6 +72,11 @@
 def str__Long(space, w_long):
     return space.wrap(str(w_long.longval))
 
+def eq__Long_Long(space, w_long1, w_long2):
+    i = w_long1.longval
+    j = w_long2.longval
+    return space.newbool( i == j )
+
 def lt__Long_Long(space, w_long1, w_long2):
     i = w_long1.longval
     j = w_long2.longval
@@ -148,10 +159,7 @@
     return W_LongObject(space, -w_long1.longval)
 
 def pos__Long(space, w_long):
-    if space.is_true(space.is_(space.type(w_long), space.w_long)):
-        return w_long
-    else:
-        return W_LongObject(space, w_long.longval)
+    return long__Long(space, w_long)
 
 def abs__Long(space, w_long):
     return W_LongObject(space, abs(w_long.longval))

Modified: pypy/trunk/src/pypy/objspace/std/objspace.py
==============================================================================
--- pypy/trunk/src/pypy/objspace/std/objspace.py	(original)
+++ pypy/trunk/src/pypy/objspace/std/objspace.py	Wed Jun 16 17:28:43 2004
@@ -259,11 +259,11 @@
             #raise TypeError, "cannot wrap classes"
         return W_CPythonObject(self, x)
 
-    def newint(self, int_w):
-        return W_IntObject(self, int_w)
+    def newint(self, intval):
+        return W_IntObject(self, intval)
 
-    def newfloat(self, int_w):
-        return W_FloatObject(self, int_w)
+    def newfloat(self, floatval):
+        return W_FloatObject(self, floatval)
 
     def newtuple(self, list_w):
         assert isinstance(list_w, list)



More information about the Pypy-commit mailing list