Author: Benjamin Peterson <[email protected]>
Branch: 
Changeset: r44409:8d950d4e5c98
Date: 2011-05-24 14:50 -0500
http://bitbucket.org/pypy/pypy/changeset/8d950d4e5c98/

Log:    long is also a reasonable thing to return from __len__ or
        __nonzero__

diff --git a/pypy/objspace/descroperation.py b/pypy/objspace/descroperation.py
--- a/pypy/objspace/descroperation.py
+++ b/pypy/objspace/descroperation.py
@@ -220,7 +220,8 @@
             return True
         w_restype = space.type(w_res)
         if (space.is_w(w_restype, space.w_bool) or
-            space.is_w(w_restype, space.w_int)):
+            space.is_w(w_restype, space.w_int) or
+            space.is_w(w_restype, space.w_long)):
             return space.int_w(w_res) != 0
         else:
             raise OperationError(space.w_TypeError,
diff --git a/pypy/objspace/test/test_descroperation.py 
b/pypy/objspace/test/test_descroperation.py
--- a/pypy/objspace/test/test_descroperation.py
+++ b/pypy/objspace/test/test_descroperation.py
@@ -524,6 +524,13 @@
         assert issubclass(B, B)
         assert issubclass(23, B)
 
+    def test_truth_of_long(self):
+        class X(object):
+            def __len__(self): return 1L
+            __nonzero__ = __len__
+        assert X()
+        del X.__nonzero__
+        assert X()
 
 class AppTestWithBuiltinShortcut(AppTest_Descroperation):
     OPTIONS = {'objspace.std.builtinshortcut': True}
_______________________________________________
pypy-commit mailing list
[email protected]
http://mail.python.org/mailman/listinfo/pypy-commit

Reply via email to