mirror of
https://github.com/python/cpython.git
synced 2025-07-19 17:25:54 +00:00
GH-91153: Handle mutating __index__ methods in bytearray item assignment (GH-94891)
(cherry picked from commit f36589510b
)
Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
This commit is contained in:
parent
d2be44230e
commit
9487e8d250
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