bytearray slice assignment fails for derived types
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
py/objarray: Fix use-after-free if extending a slice from itself.
Closes https://github.com/micropython/micropython/issues/13283 which reported this bug when assigning to a slice, also fixes a related bug when a bytearray is extended by itself (h/t @dpgeorge for spotting.) Unit tests added for both.
There is a related much more nefarious set of bugs when a bytearray or similar is targeted by a memoryview and then resized. For now these are not fixed, but have pushed a commit here to document this case as a difference from CPython.
Reproducing this bug and confirming the fix was done by running the unix port under valgrind with GC-aware extensions (PR at https://github.com/micropython/micropython/pull/14196).
Note in default configurations with GIL this bug exists but has no impact (the free buffer won't have new data written to it while the function is still executing, and is no longer referenced after the function returns).