QUERY · ISSUE
Unix: CPython incompatibility assigning negative values to bytearrays.
py-core
This is arguably minor, but I thought it worth flagging up. It also applies to bytes objects.
MicroPython v1.8.7-893-g46b849a on 2017-06-22; linux version
Use Ctrl-D to exit, Ctrl-E for paste mode
>>> a = bytearray([0, 1, -1])
>>> a[2]
255
>>>
Under CPython 3.4.3:
>>> a = bytearray([0, 1, -1])
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ValueError: byte must be in range(0, 256)
CANDIDATE · ISSUE
bytearray slice assignment from generator produces error
Is this an intentional "micro" difference from Cpython or an oversight? This works in Cpython but produces a "Not implemented" error in MicroPython (on Pyboard).
b = bytearray(20)
b[2:7] = (1 for x in range(5))
While the following workround is trivial I thought it worth flagging up:
b[2:7] = bytes(1 for x in range(5))