summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_bytes.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2022-07-19 17:12:39 (GMT)
committerGitHub <noreply@github.com>2022-07-19 17:12:39 (GMT)
commit9487e8d250783b48eec1d240eddac809584e11a0 (patch)
treeffa7c82293503d235d501bd2c7b7d7ec2495c60e /Lib/test/test_bytes.py
parentd2be44230eaade5c367af6ec9df649502b574dac (diff)
downloadcpython-9487e8d250783b48eec1d240eddac809584e11a0.zip
cpython-9487e8d250783b48eec1d240eddac809584e11a0.tar.gz
cpython-9487e8d250783b48eec1d240eddac809584e11a0.tar.bz2
GH-91153: Handle mutating __index__ methods in bytearray item assignment (GH-94891)
(cherry picked from commit f36589510b8708fa224d799d5b328deab558aa4e) Co-authored-by: Brandt Bucher <brandtbucher@microsoft.com>
Diffstat (limited to 'Lib/test/test_bytes.py')
-rw-r--r--Lib/test/test_bytes.py17
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):
#