[pypy-svn] r66101 - in pypy/trunk/pypy/module/__builtin__: . test

antocuni at codespeak.net antocuni at codespeak.net
Fri Jul 3 14:32:48 CEST 2009


Author: antocuni
Date: Fri Jul  3 14:32:48 2009
New Revision: 66101

Modified:
   pypy/trunk/pypy/module/__builtin__/functional.py
   pypy/trunk/pypy/module/__builtin__/test/test_range.py
Log:
(brian brazil, antocuni, Harald Massa around, based on a patch by jasonpjason)
a test and a fix (the contributors line was already too long to write a longer commit message :-))


Modified: pypy/trunk/pypy/module/__builtin__/functional.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/functional.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/functional.py	Fri Jul  3 14:32:48 2009
@@ -62,17 +62,15 @@
 
     try:
         # save duplication by redirecting every error to applevel
-        x = space.int_w(w_x)
+        x = space.int_w(space.int(w_x))
         if space.is_w(w_y, space.w_None):
             start, stop = 0, x
         else:
-            start, stop = x, space.int_w(w_y)
-        step = space.int_w(w_step)
+            start, stop = x, space.int_w(space.int(w_y))
+        step = space.int_w(space.int(w_step))
         howmany = get_len_of_range(start, stop, step)
     except OperationError, e:
         if not e.match(space, space.w_TypeError):
-            pass
-        else:
             raise
     except (ValueError, OverflowError):
         pass

Modified: pypy/trunk/pypy/module/__builtin__/test/test_range.py
==============================================================================
--- pypy/trunk/pypy/module/__builtin__/test/test_range.py	(original)
+++ pypy/trunk/pypy/module/__builtin__/test/test_range.py	Fri Jul  3 14:32:48 2009
@@ -17,7 +17,6 @@
    def test_range_negstartisstop(self):
       assert range(-1, -1) == []
 
-
    def test_range_zero(self):
       assert range(0) == []
 
@@ -67,3 +66,13 @@
    def test_range_wrong_type(self):
        raises(TypeError, range, "42")
 
+   def test_range_object_with___int__(self):
+       class A(object):
+           def __int__(self):
+               return 5
+
+       assert range(A()) == [0, 1, 2, 3, 4]
+       assert range(0, A()) == [0, 1, 2, 3, 4]
+       assert range(0, 10, A()) == [0, 5]
+
+



More information about the Pypy-commit mailing list