mirror of
https://github.com/python/cpython.git
synced 2025-07-24 11:44:31 +00:00
Issue #19414: Have the OrderedDict mark deleted links as unusable.
This gives an earlier and more visible failure if a link is deleted during iteration.
This commit is contained in:
parent
71ac07f8ba
commit
53d2c41f77
3 changed files with 15 additions and 0 deletions
|
@ -1193,6 +1193,16 @@ class TestOrderedDict(unittest.TestCase):
|
|||
[t[1] for t in reversed(pairs)])
|
||||
self.assertEqual(list(reversed(od.items())), list(reversed(pairs)))
|
||||
|
||||
def test_detect_deletion_during_iteration(self):
|
||||
od = OrderedDict.fromkeys('abc')
|
||||
it = iter(od)
|
||||
key = next(it)
|
||||
del od[key]
|
||||
with self.assertRaises(Exception):
|
||||
# Note, the exact exception raised is not guaranteed
|
||||
# The only guarantee that the next() will not succeed
|
||||
next(it)
|
||||
|
||||
def test_popitem(self):
|
||||
pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)]
|
||||
shuffle(pairs)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue