mirror of
https://github.com/python/cpython.git
synced 2025-10-14 10:53:40 +00:00
Issue #22077: Improve index error messages for bytearrays, bytes, lists, and
tuples by adding 'or slices'. Added ', not <typename' for bytearrays. Original patch by Claudiu Popa.
This commit is contained in:
parent
7f9cc9359b
commit
ffff1440d1
8 changed files with 45 additions and 6 deletions
|
@ -699,6 +699,11 @@ class BaseBytesTest:
|
|||
class BytesTest(BaseBytesTest, unittest.TestCase):
|
||||
type2test = bytes
|
||||
|
||||
def test_getitem_error(self):
|
||||
msg = "byte indices must be integers or slices"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
b'python'['a']
|
||||
|
||||
def test_buffer_is_readonly(self):
|
||||
fd = os.open(__file__, os.O_RDONLY)
|
||||
with open(fd, "rb", buffering=0) as f:
|
||||
|
@ -753,6 +758,17 @@ class BytesTest(BaseBytesTest, unittest.TestCase):
|
|||
class ByteArrayTest(BaseBytesTest, unittest.TestCase):
|
||||
type2test = bytearray
|
||||
|
||||
def test_getitem_error(self):
|
||||
msg = "bytearray indices must be integers or slices"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
bytearray(b'python')['a']
|
||||
|
||||
def test_setitem_error(self):
|
||||
msg = "bytearray indices must be integers or slices"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
b = bytearray(b'python')
|
||||
b['a'] = "python"
|
||||
|
||||
def test_nohash(self):
|
||||
self.assertRaises(TypeError, hash, bytearray())
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue