mirror of
https://github.com/python/cpython.git
synced 2025-08-04 00:48:58 +00:00
GH-91153: Handle mutating __index__ methods in bytearray item assignment (GH-94891)
This commit is contained in:
parent
3f738600f6
commit
f36589510b
4 changed files with 60 additions and 11 deletions
|
@ -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):
|
||||
#
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue