Author: Armin Rigo <ar...@tunes.org> Branch: py3.5 Changeset: r88886:2b00c209938d Date: 2016-12-04 22:00 +0100 http://bitbucket.org/pypy/pypy/changeset/2b00c209938d/
Log: Test and fix 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 @@ -90,11 +90,15 @@ 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) 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) # extremely obscure case w_obj = space.allocate_instance(W_IntObject, w_inttype) W_IntObject.__init__(w_obj, as_int) return w_obj diff --git a/pypy/objspace/std/test/test_boolobject.py b/pypy/objspace/std/test/test_boolobject.py --- a/pypy/objspace/std/test/test_boolobject.py +++ b/pypy/objspace/std/test/test_boolobject.py @@ -84,3 +84,7 @@ def __bool__(self): return 1 raises(TypeError, bool, Spam()) + + def test_from_bytes(self): + assert bool.from_bytes(b"", 'little') is False + assert bool.from_bytes(b"dasijldjs" * 157, 'little') is True 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 @@ -607,6 +607,16 @@ assert int(bytearray(b'100'), 2) == 4 raises(TypeError, int, memoryview(b'100'), 2) + def test_from_bytes(self): + class X(int): + pass + x = X.from_bytes(b"", 'little') + assert type(x) is X and x == 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('*') + class AppTestIntShortcut(AppTestInt): spaceconfig = {"objspace.std.intshortcut": True} _______________________________________________ pypy-commit mailing list pypy-commit@python.org https://mail.python.org/mailman/listinfo/pypy-commit