mirror of
https://github.com/python/cpython.git
synced 2025-12-04 00:30:19 +00:00
Fix OrderedDict.setdefault() to work for subclasses that define __missing__().
This commit is contained in:
parent
ed13853e5d
commit
a673b1fd0e
3 changed files with 16 additions and 1 deletions
|
|
@ -976,6 +976,12 @@ class TestOrderedDict(unittest.TestCase):
|
|||
# make sure 'x' is added to the end
|
||||
self.assertEqual(list(od.items())[-1], ('x', 10))
|
||||
|
||||
# make sure setdefault still works when __missing__ is defined
|
||||
class Missing(OrderedDict):
|
||||
def __missing__(self, key):
|
||||
return 0
|
||||
self.assertEqual(Missing().setdefault(5, 9), 9)
|
||||
|
||||
def test_reinsert(self):
|
||||
# Given insert a, insert b, delete a, re-insert a,
|
||||
# verify that a is now later than b.
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue