Currently, the array constructor, if given a bytearray, detects this with PyByteArray_Check, and hands it on to array_fromstring, which does not support bytearray (by using "s#" with PyArg_ParseTuple) and raises TypeError.
>>> array('h', bytearray(b'xyxyxyxyxyxyxyxyxy'))
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: must be bytes or read-only buffer, not bytearray
>>>
I see no reason to insist on read-only buffers. I'm attaching a patch that I think fixes this. |