summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/list_tests.py8
-rw-r--r--Lib/test/test_list.py14
2 files changed, 22 insertions, 0 deletions
diff --git a/Lib/test/list_tests.py b/Lib/test/list_tests.py
index 89cd10f..dbc5ef4 100644
--- a/Lib/test/list_tests.py
+++ b/Lib/test/list_tests.py
@@ -191,6 +191,14 @@ class CommonTest(seq_tests.CommonTest):
self.assertRaises(TypeError, a.__setitem__)
+ def test_slice_assign_iterator(self):
+ x = self.type2test(range(5))
+ x[0:3] = reversed(range(3))
+ self.assertEqual(x, self.type2test([2, 1, 0, 3, 4]))
+
+ x[:] = reversed(range(3))
+ self.assertEqual(x, self.type2test([2, 1, 0]))
+
def test_delslice(self):
a = self.type2test([0, 1])
del a[1:2]
diff --git a/Lib/test/test_list.py b/Lib/test/test_list.py
index d21429f..4d2d547 100644
--- a/Lib/test/test_list.py
+++ b/Lib/test/test_list.py
@@ -245,6 +245,20 @@ class ListTest(list_tests.CommonTest):
with self.assertRaises(TypeError):
a[0] < a
+ def test_list_index_modifing_operand(self):
+ # See gh-120384
+ class evil:
+ def __init__(self, lst):
+ self.lst = lst
+ def __iter__(self):
+ yield from self.lst
+ self.lst.clear()
+
+ lst = list(range(5))
+ operand = evil(lst)
+ with self.assertRaises(ValueError):
+ lst[::-1] = operand
+
@cpython_only
def test_preallocation(self):
iterable = [0] * 10