[pypy-svn] pypy default: Fix long(x) returning whatever __long__ returns without converting it to long

bivab commits-noreply at bitbucket.org
Fri Jan 21 15:11:34 CET 2011


Author: David Schneider <david.schneider at picle.org>
Branch: 
Changeset: r41135:0bb85a41b51d
Date: 2011-01-21 15:09 +0100
http://bitbucket.org/pypy/pypy/changeset/0bb85a41b51d/

Log:	Fix long(x) returning whatever __long__ returns without converting
	it to long

diff --git a/pypy/objspace/std/test/test_longobject.py b/pypy/objspace/std/test/test_longobject.py
--- a/pypy/objspace/std/test/test_longobject.py
+++ b/pypy/objspace/std/test/test_longobject.py
@@ -310,3 +310,16 @@
         x = eval("-0L")
         assert x == 0L
 
+    def test_mix_int_and_long(self):
+        class IntLongMixClass(object):
+            def __int__(self):
+                return 42L
+
+            def __long__(self):
+                return 64
+
+        mixIntAndLong = IntLongMixClass()
+        as_long = long(mixIntAndLong)
+        assert type(as_long) is long
+        assert as_long == 64
+

diff --git a/pypy/objspace/std/longtype.py b/pypy/objspace/std/longtype.py
--- a/pypy/objspace/std/longtype.py
+++ b/pypy/objspace/std/longtype.py
@@ -14,6 +14,7 @@
 
 def descr__new__(space, w_longtype, w_x=0, w_base=gateway.NoneNotWrapped):
     from pypy.objspace.std.longobject import W_LongObject
+
     w_value = w_x     # 'x' is the keyword argument name in CPython
     if w_base is None:
         # check for easy cases
@@ -48,9 +49,6 @@
                     w_obj = space.long(w_obj)
                 else:
                     w_obj = space.int(w_obj)
-            # 'long(x)' should return whatever x.__long__() returned
-            if space.is_w(w_longtype, space.w_long):
-                return w_obj
             if space.is_true(space.isinstance(w_obj, space.w_long)):
                 assert isinstance(w_obj, W_LongObject)  # XXX this could fail!
                 # XXX find a way to do that even if w_obj is not a W_LongObject


More information about the Pypy-commit mailing list