cpython: a3c345ba3563 (original) (raw)

Mercurial > cpython

changeset 90558:a3c345ba3563

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. [#19414]

Raymond Hettinger python@rcn.com
date Sat, 03 May 2014 21:58:45 -0700
parents 7f6d9990a9b1
children 3aa5fae8c313
files Lib/collections/__init__.py Lib/test/test_collections.py Misc/NEWS
diffstat 3 files changed, 15 insertions(+), 0 deletions(-)[+] [-] Lib/collections/__init__.py 2 Lib/test/test_collections.py 10 Misc/NEWS 3

line wrap: on

line diff

--- a/Lib/collections/init.py +++ b/Lib/collections/init.py @@ -96,6 +96,8 @@ class OrderedDict(dict): link_next = link.next link_prev.next = link_next link_next.prev = link_prev

def iter(self): 'od.iter() <==> iter(od)'

--- a/Lib/test/test_collections.py +++ b/Lib/test/test_collections.py @@ -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_popitem(self): pairs = [('c', 1), ('b', 2), ('a', 3), ('d', 4), ('e', 5), ('f', 6)] shuffle(pairs)

--- a/Misc/NEWS +++ b/Misc/NEWS @@ -73,6 +73,9 @@ Library Decimal.quantize() method in the Python version. It had never been present in the C version. +- Issue #19414: Have the OrderedDict mark deleted links as unusable.