← index #1710Issue #4810
Related · medium · value 2.484
QUERY · ISSUE

bytearray slice assignment fails for derived types

openby mbueschopened 2015-12-11updated 2024-08-28
docs

The type check for slice assignment to bytearray derived types seems to be a bit too strict:

class MyBytearray(bytearray): pass

a = MyBytearray(4)
b = MyBytearray(4)
a[0:4] = b

results in this error:

Traceback (most recent call last):
  File "test.py", line 5, in <module>
NotImplementedError: array/bytes required on right side
CANDIDATE · ISSUE

bytesarray buffer manipulation/copy fail

closedby nedoskivopened 2019-05-23updated 2019-05-23

Hello,

I'm not a big expert at this, so I googled a little and found this topic:

https://stackoverflow.com/questions/10633881/how-to-copy-a-python-bytearray-buffer

but it do not work for me:

`c=b'\x11\x11'

a=b'\xff\xff'
a[:]=c
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: 'bytes' object doesn't support item assignment`

Also tried to change in lots of way value of any byte in the array it returns same error. Did I do something wrong or there is something not yet implemented?

Keyboard

j / / n
next pair
k / / p
previous pair
1 / / h
show query pane
2 / / l
show candidate pane
c
copy suggested comment
r
toggle reasoning
g i
go to index
?
show this help
esc
close overlays

press ? or esc to close

copied