diff options
author | Brandt Bucher <brandtbucher@microsoft.com> | 2022-07-19 16:42:40 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-07-19 16:42:40 (GMT) |
commit | f36589510b8708fa224d799d5b328deab558aa4e (patch) | |
tree | 3a6268e6af9ad9984dbb6a52d13e454582742cab /Lib | |
parent | 3f738600f623b88bc90ec12587f75babb6f1025e (diff) | |
download | cpython-f36589510b8708fa224d799d5b328deab558aa4e.zip cpython-f36589510b8708fa224d799d5b328deab558aa4e.tar.gz cpython-f36589510b8708fa224d799d5b328deab558aa4e.tar.bz2 |
GH-91153: Handle mutating __index__ methods in bytearray item assignment (GH-94891)
Diffstat (limited to 'Lib')
-rw-r--r-- | Lib/test/test_bytes.py | 17 |
1 files changed, 17 insertions, 0 deletions
diff --git a/Lib/test/test_bytes.py b/Lib/test/test_bytes.py index b457ff6..521e391 100644 --- a/Lib/test/test_bytes.py +++ b/Lib/test/test_bytes.py @@ -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): # |