[pypy-commit] pypy py3.5: Make the test more precise, fix (thanks ronan)

arigo pypy.commits at gmail.com
Mon Dec 5 06:13:29 EST 2016


Author: Armin Rigo <arigo at tunes.org>
Branch: py3.5
Changeset: r88890:2c5fdace2d2e
Date: 2016-12-05 12:12 +0100
http://bitbucket.org/pypy/pypy/changeset/2c5fdace2d2e/

Log:	Make the test more precise, fix (thanks ronan)

diff --git a/pypy/objspace/std/intobject.py b/pypy/objspace/std/intobject.py
--- a/pypy/objspace/std/intobject.py
+++ b/pypy/objspace/std/intobject.py
@@ -89,19 +89,13 @@
         try:
             as_int = bigint.toint()
         except OverflowError:
-            from pypy.objspace.std.longobject import newbigint
-            if space.is_w(w_inttype, space.w_bool):
-                return space.w_True      # extremely obscure case
-            return newbigint(space, w_inttype, bigint)
+            w_obj = space.newlong_from_rbigint(bigint)
         else:
-            if space.is_w(w_inttype, space.w_int):
-                # common case
-                return wrapint(space, as_int)
-            if space.is_w(w_inttype, space.w_bool):
-                return space.newbool(as_int != 0)     # extremely obscure case
-            w_obj = space.allocate_instance(W_IntObject, w_inttype)
-            W_IntObject.__init__(w_obj, as_int)
-            return w_obj
+            w_obj = space.newint(as_int)
+        if not space.is_w(w_inttype, space.w_int):
+            # That's what from_bytes() does in CPython 3.5.2 too
+            w_obj = space.call_function(w_inttype, w_obj)
+        return w_obj
 
     @unwrap_spec(nbytes=int, byteorder=str, signed=bool)
     def descr_to_bytes(self, space, nbytes, byteorder, signed=False):
diff --git a/pypy/objspace/std/test/test_intobject.py b/pypy/objspace/std/test/test_intobject.py
--- a/pypy/objspace/std/test/test_intobject.py
+++ b/pypy/objspace/std/test/test_intobject.py
@@ -608,14 +608,18 @@
         raises(TypeError, int, memoryview(b'100'), 2)
 
     def test_from_bytes(self):
+        called = []
         class X(int):
-            pass
+            def __init__(self, val):
+                called.append(val)
         x = X.from_bytes(b"", 'little')
         assert type(x) is X and x == 0
+        assert called == [0]
         x = X.from_bytes(b"*" * 100, 'little')
         assert type(x) is X
-        expected = sum(256 ** i for i in range(100))
-        assert x == expected * ord('*')
+        expected = sum(256 ** i for i in range(100)) * ord('*')
+        assert x == expected
+        assert called == [0, expected]
 
 
 class AppTestIntShortcut(AppTestInt):


More information about the pypy-commit mailing list