mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +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
|
@ -30,6 +30,12 @@ class CommonTest(seq_tests.CommonTest):
|
|||
self.assertNotEqual(id(a), id(b))
|
||||
self.assertEqual(a, b)
|
||||
|
||||
def test_getitem_error(self):
|
||||
msg = "list indices must be integers or slices"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
a = []
|
||||
a['a'] = "python"
|
||||
|
||||
def test_repr(self):
|
||||
l0 = []
|
||||
l2 = [0, 1, 2]
|
||||
|
@ -120,6 +126,10 @@ class CommonTest(seq_tests.CommonTest):
|
|||
a[-1] = 9
|
||||
self.assertEqual(a, self.type2test([5,6,7,8,9]))
|
||||
|
||||
msg = "list indices must be integers or slices"
|
||||
with self.assertRaisesRegex(TypeError, msg):
|
||||
a['a'] = "python"
|
||||
|
||||
def test_delitem(self):
|
||||
a = self.type2test([0, 1])
|
||||
del a[1]
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue