Python 3.15 reimplemented bytearray using an internal bytes object (to implement the bytearray.take_bytes() method). _PyBytes_Resize() is used internally to resize the bytearray object. Problem: if _PyBytes_Resize() fails, the bytearray object is cleared.
On Python 3.14, the bytearray is not cleared on resize failure.
The following example works on Python 3.14 but fails on Python 3.15.
import _testcapi
data = b'some data'
ba = bytearray(data)
try:
try:
_testcapi.set_nomemory(0)
ba.resize(1024)
except MemoryError:
pass
else:
raise AssertionError("expect MemoryError")
finally:
_testcapi.remove_mem_hooks()
if ba != data:
raise AssertionError(f"{ba} != {data}")
Linked PRs
Python 3.15 reimplemented bytearray using an internal bytes object (to implement the
bytearray.take_bytes()method)._PyBytes_Resize()is used internally to resize the bytearray object. Problem: if_PyBytes_Resize()fails, the bytearray object is cleared.On Python 3.14, the bytearray is not cleared on resize failure.
The following example works on Python 3.14 but fails on Python 3.15.
Linked PRs