bpo-36473: add maximum iteration check for dict .values() and .items() (GH-12619)

This commit is contained in:
Thomas Perl 2019-04-02 11:30:10 +02:00 committed by Inada Naoki
parent 04694a306b
commit b8311cf5e5
3 changed files with 36 additions and 2 deletions

View file

@ -477,7 +477,25 @@ class DictTest(unittest.TestCase):
with self.assertRaises(RuntimeError):
for i in d:
del d[0]
d[1] = 1
d[0] = 0
def test_mutating_iteration_delete_over_values(self):
# change dict content during iteration
d = {}
d[0] = 0
with self.assertRaises(RuntimeError):
for i in d.values():
del d[0]
d[0] = 0
def test_mutating_iteration_delete_over_items(self):
# change dict content during iteration
d = {}
d[0] = 0
with self.assertRaises(RuntimeError):
for i in d.items():
del d[0]
d[0] = 0
def test_mutating_lookup(self):
# changing dict during a lookup (issue #14417)