This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Cannot assign memoryview values from array.array
Type: behavior Stage: resolved
Components: Library (Lib) Versions: Python 3.6
process
Status: closed Resolution: not a bug
Dependencies: Superseder:
Assigned To: skrah Nosy List: aparamon, skrah, xtreak
Priority: normal Keywords:

Created on 2018-10-05 12:24 by aparamon, last changed 2022-04-11 14:59 by admin. This issue is now closed.

Messages (2)
msg327133 - (view) Author: Andrey Paramonov (aparamon) Date: 2018-10-05 12:24
Currently, memoryview values can be assigned from all bytes-like objects (https://docs.python.org/3/glossary.html#term-bytes-like-object) except byte array.array:

----
import array

mview = memoryview(bytearray(b'hello'))

mview[:] = bytes(b'hello')  # success
mview[:] = bytearray(b'hello')  # success
mview[:] = memoryview(b'hello')  # success
mview[:] = array.array('b', b'hello')  # fail
----
    mview[:] = array.array('b', b'hello')
ValueError: memoryview assignment: lvalue and rvalue have different structures
----
msg327240 - (view) Author: Stefan Krah (skrah) * (Python committer) Date: 2018-10-06 09:59
>>> mview.format
'B'
>>> mview[:] = array.array('B', b'hello')


Bytes have format 'B', so this works as expected.
History
Date User Action Args
2022-04-11 14:59:06adminsetgithub: 79086
2018-10-06 09:59:56skrahsetstatus: open -> closed

assignee: skrah

nosy: + skrah
messages: + msg327240
resolution: not a bug
stage: resolved
2018-10-06 08:48:13xtreaksetnosy: + xtreak
2018-10-05 12:24:52aparamoncreate