32ef3a3517
Behaviour of array initialisation is subtly different for bytes, bytearray and array.array when argument has buffer protocol. This patch gets us CPython conformant (except we allow initialisation of array.array by buffer with length not a multiple of typecode).
15 lines
316 B
Python
15 lines
316 B
Python
# test construction of bytes from different objects
|
|
|
|
from array import array
|
|
|
|
# tuple, list, bytearray
|
|
print(bytes((1, 2)))
|
|
print(bytes([1, 2]))
|
|
print(bytes(bytearray(4)))
|
|
|
|
# arrays
|
|
print(bytes(array('b', [1, 2])))
|
|
print(bytes(array('h', [1, 2])))
|
|
print(bytes(array('I', [1, 2])))
|
|
print(bytes(array('f', [1, 2.3])))
|