mirror of
https://github.com/python/cpython.git
synced 2025-08-31 05:58:33 +00:00
#4170: Fix segfault when pickling a defauldict object.
The 2.x dict.iteritems() returns an iterator, whereas the 3.0 dict.items() returns a "view", which is iterable, but not an iterator with its __next__ method. Patch by Hirokazu Yamamoto.
This commit is contained in:
parent
73b90a8d61
commit
f43ee81ef2
3 changed files with 20 additions and 1 deletions
|
@ -2,6 +2,7 @@
|
|||
|
||||
import os
|
||||
import copy
|
||||
import pickle
|
||||
import tempfile
|
||||
import unittest
|
||||
from test import support
|
||||
|
@ -164,6 +165,13 @@ class TestDefaultDict(unittest.TestCase):
|
|||
finally:
|
||||
os.remove(tfn)
|
||||
|
||||
def test_pickleing(self):
|
||||
d = defaultdict(int)
|
||||
d[1]
|
||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||
s = pickle.dumps(d, proto)
|
||||
o = pickle.loads(s)
|
||||
self.assertEqual(d, o)
|
||||
|
||||
def test_main():
|
||||
support.run_unittest(TestDefaultDict)
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue