[pypy-svn] r58738 - in pypy/branch/2.5-merge/pypy/objspace/std: . test

arigo at codespeak.net arigo at codespeak.net
Tue Oct 7 14:31:43 CEST 2008


Author: arigo
Date: Tue Oct  7 14:31:42 2008
New Revision: 58738

Modified:
   pypy/branch/2.5-merge/pypy/objspace/std/inttype.py
   pypy/branch/2.5-merge/pypy/objspace/std/test/test_intobject.py
Log:
(jlg, arigo)
Test and fix for subclasses of 'int' that override __int__().


Modified: pypy/branch/2.5-merge/pypy/objspace/std/inttype.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/objspace/std/inttype.py	(original)
+++ pypy/branch/2.5-merge/pypy/objspace/std/inttype.py	Tue Oct  7 14:31:42 2008
@@ -55,7 +55,7 @@
     value = 0
     if w_base is None:
         # check for easy cases
-        if isinstance(w_value, W_IntObject):
+        if type(w_value) is W_IntObject:
             value = w_value.intval
         elif space.is_true(space.isinstance(w_value, space.w_str)):
             try:

Modified: pypy/branch/2.5-merge/pypy/objspace/std/test/test_intobject.py
==============================================================================
--- pypy/branch/2.5-merge/pypy/objspace/std/test/test_intobject.py	(original)
+++ pypy/branch/2.5-merge/pypy/objspace/std/test/test_intobject.py	Tue Oct  7 14:31:42 2008
@@ -417,7 +417,16 @@
 
         class b(object): 
             pass 
-        raises((AttributeError,TypeError), long, b()) 
+        raises((AttributeError,TypeError), long, b())
+
+    def test_override___int__(self):
+        class myint(int):
+            def __int__(self):
+                return 42
+        assert int(myint(21)) == 42
+        class myotherint(int):
+            pass
+        assert int(myotherint(21)) == 21
 
     def test_getnewargs(self):
         assert  0 .__getnewargs__() == (0,)



More information about the Pypy-commit mailing list