Commits

Philip Jenvey committed dcd5c7c

fix from_bytes on iterables of ints

  • Participants
  • Parent commits b1a4f4d
  • Branches py3k

Comments (0)

Files changed (2)

pypy/objspace/std/longtype.py

         raise OperationError(space.w_OverflowError,
                              space.wrap("too many digits in integer"))
 
-@unwrap_spec(s='bufferstr', byteorder=str, signed=bool)
-def descr_from_bytes(space, w_cls, s, byteorder, signed=False):
+@unwrap_spec(byteorder=str, signed=bool)
+def descr_from_bytes(space, w_cls, w_obj, byteorder, signed=False):
+    bytes = space.bytes_w(space.call_function(space.w_bytes, w_obj))
     try:
-        bigint = rbigint.frombytes(s, byteorder=byteorder, signed=signed)
+        bigint = rbigint.frombytes(bytes, byteorder=byteorder, signed=signed)
     except InvalidEndiannessError:
         raise OperationError(
             space.w_ValueError,

pypy/objspace/std/test/test_longobject.py

         assert int.from_bytes(b'\x01\x01', 'little') == 257
         assert int.from_bytes(b'\x01\x00', 'big') == 256
         assert int.from_bytes(b'\x00\x80', 'little', signed=True) == -32768
+        assert int.from_bytes([255, 0, 0], 'big', signed=True) == -65536
         raises(TypeError, int.from_bytes, '', 'big')
         raises(ValueError, int.from_bytes, b'c', 'foo')