py: Allow bytes/bytearray/array to be init'd by buffer protocol objects.
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).
This commit is contained in:
14
tests/basics/bytearray_construct.py
Normal file
14
tests/basics/bytearray_construct.py
Normal file
@@ -0,0 +1,14 @@
|
||||
# test construction of bytearray from different objects
|
||||
|
||||
from array import array
|
||||
|
||||
# bytes, tuple, list
|
||||
print(bytearray(b'123'))
|
||||
print(bytearray((1, 2)))
|
||||
print(bytearray([1, 2]))
|
||||
|
||||
# arrays
|
||||
print(bytearray(array('b', [1, 2])))
|
||||
print(bytearray(array('h', [1, 2])))
|
||||
print(bytearray(array('I', [1, 2])))
|
||||
print(bytearray(array('f', [1, 2.3])))
|
||||
Reference in New Issue
Block a user