GH-91153: Handle mutating __index__ methods in bytearray item assignment (GH-94891)

This commit is contained in:
Brandt Bucher 2022-07-19 09:42:40 -07:00 committed by GitHub
parent 3f738600f6
commit f36589510b
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
4 changed files with 60 additions and 11 deletions

View file

@ -1710,6 +1710,23 @@ class ByteArrayTest(BaseBytesTest, unittest.TestCase):
self.assertEqual(b1, b)
self.assertEqual(b3, b'xcxcxc')
def test_mutating_index(self):
class Boom:
def __index__(self):
b.clear()
return 0
with self.subTest("tp_as_mapping"):
b = bytearray(b'Now you see me...')
with self.assertRaises(IndexError):
b[0] = Boom()
with self.subTest("tp_as_sequence"):
_testcapi = import_helper.import_module('_testcapi')
b = bytearray(b'Now you see me...')
with self.assertRaises(IndexError):
_testcapi.sequence_setitem(b, 0, Boom())
class AssortedBytesTest(unittest.TestCase):
#