Author jeff.allen
Recipients jeff.allen,
Date 2018-11-28.21:21:02
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <>
Actually, this isn't quite the problem I thought. PyArray supports the buffer interface because in CPython you can write:

>>> ab = array.array('b', [65, 66, 67])
>>> list(buffer(ab))
['A', 'B', 'C']
>>> ai = array.array('i', [65, 66, 67])
>>> list(buffer(ai))
['A', '\x00', '\x00', '\x00', 'B', '\x00', '\x00', '\x00', 'C', '\x00', '\x00', '\x00']

(Little-endian machine: YMMV, and Java is big-endian.)

In Jython we have only one (internal) BufferProtocol so the side-effect of supporting buffer() as we should is that array.array also responds to memoryview().

However, if array.array were to respond to memoryview(), as it does in Python 3, it should do so with a properly structured buffer, that is:
>>> mi = memoryview(ai)
>>> mi.itemsize, mi.format, mi.shape
(4, 'i', (3,))

For compatibility with CPython 2, it probably shouldn't try.
Date User Action Args
2018-11-28 21:21:02jeff.allensetmessageid: <>
2018-11-28 21:21:02jeff.allensetrecipients: + jeff.allen,
2018-11-28 21:21:02jeff.allenlinkissue2715 messages
2018-11-28 21:21:02jeff.allencreate