[pypy-commit] pypy issue-2248: fix for issue #2248, can W_Float.int() be removed?

mattip pypy.commits at gmail.com
Wed Mar 2 00:30:00 EST 2016


Author: mattip <matti.picus at gmail.com>
Branch: issue-2248
Changeset: r82650:64144f654a33
Date: 2016-03-02 00:27 -0500
http://bitbucket.org/pypy/pypy/changeset/64144f654a33/

Log:	fix for issue #2248, can W_Float.int() be removed?

diff --git a/pypy/module/__builtin__/test/test_classobj.py b/pypy/module/__builtin__/test/test_classobj.py
--- a/pypy/module/__builtin__/test/test_classobj.py
+++ b/pypy/module/__builtin__/test/test_classobj.py
@@ -452,7 +452,6 @@
         assert a + 1 == 2
         assert a + 1.1 == 2
 
-
     def test_binaryop_calls_coerce_always(self):
         l = []
         class A:
@@ -1076,6 +1075,16 @@
         assert (D() >  A()) == 'D:A.gt'
         assert (D() >= A()) == 'D:A.ge'
 
+    def test_override___int__(self):
+        class F(float):
+            def __int__(self):
+                return 666
+        f = F(-12.3)
+        assert int(f) == 666
+        # on cpython, this calls float_trunc() in floatobject.c
+        # which ends up calling PyFloat_AS_DOUBLE((PyFloatObject*) f)
+        assert float.__int__(f) == -12
+
 
 class AppTestOldStyleClassBytesDict(object):
     def setup_class(cls):
diff --git a/pypy/objspace/std/floatobject.py b/pypy/objspace/std/floatobject.py
--- a/pypy/objspace/std/floatobject.py
+++ b/pypy/objspace/std/floatobject.py
@@ -661,7 +661,7 @@
     __format__ = interp2app(W_FloatObject.descr_format),
     __coerce__ = interp2app(W_FloatObject.descr_coerce),
     __nonzero__ = interp2app(W_FloatObject.descr_nonzero),
-    __int__ = interp2app(W_FloatObject.int),
+    __int__ = interp2app(W_FloatObject.descr_trunc),
     __float__ = interp2app(W_FloatObject.descr_float),
     __long__ = interp2app(W_FloatObject.descr_long),
     __trunc__ = interp2app(W_FloatObject.descr_trunc),


More information about the pypy-commit mailing list