[pypy-svn] r75070 - in pypy/trunk/pypy/rlib: . test

arigo at codespeak.net arigo at codespeak.net
Thu Jun 3 20:07:22 CEST 2010


Author: arigo
Date: Thu Jun  3 20:07:19 2010
New Revision: 75070

Modified:
   pypy/trunk/pypy/rlib/rarithmetic.py
   pypy/trunk/pypy/rlib/test/test_rarithmetic.py
Log:
Merge branch/int_is_not_intmask: removes the __int__() in class base_int(long),
which returns an integer of a different value than 'self'.  That causes
surprizes, e.g. doing  '%d' % x  actually call x.__int__() on PyPy but not on
CPython.  I think that both behaviors are acceptable -- on PyPy we generally
call __xyz__() methods more often than CPython does.


Modified: pypy/trunk/pypy/rlib/rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/rarithmetic.py	(original)
+++ pypy/trunk/pypy/rlib/rarithmetic.py	Thu Jun  3 20:07:19 2010
@@ -178,12 +178,6 @@
         else:
             return super(base_int, klass).__new__(klass, val)
 
-    def __int__(self):
-        if self < LONG_TEST:
-            return long.__int__(self)
-        else:
-            return intmask(self)
-
     def __add__(self, other):
         x = long(self)
         y = long(other)

Modified: pypy/trunk/pypy/rlib/test/test_rarithmetic.py
==============================================================================
--- pypy/trunk/pypy/rlib/test/test_rarithmetic.py	(original)
+++ pypy/trunk/pypy/rlib/test/test_rarithmetic.py	Thu Jun  3 20:07:19 2010
@@ -114,7 +114,10 @@
         #self.binary_test(lambda x, y: pow(x, y, 42), (2, 3, 5, 1000))
 
     def test_back_to_int(self):
-        assert int(r_uint(-1)) == -1
+        #assert int(r_uint(-1)) == -1
+        # ^^^ that looks wrong IMHO: int(x) should not by itself return
+        #     an integer that has a different value than x, especially
+        #     if x is a subclass of long.
         assert int(r_uint(1)) == 1
 
     def unary_test(self, f):



More information about the Pypy-commit mailing list