← index #1710PR #6250
Off-topic · high · value 0.625
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 · PULL REQUEST

py: Fixed case where shifting a memory view right corrupts the contents

closedby dhylandsopened 2020-07-16updated 2020-07-17
py-core

The following snippet (added to the tests) demonstrates the failure:

b = bytearray(b'0123456789')
m = memoryview(b)
m[1:] = m[:-1]
print(m == b'0012345678')

The errant behaviour was observed on a PYBV11 but works fine on the
unix port.

Fixes #6244

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