mirror of
https://github.com/python/cpython.git
synced 2024-11-21 21:09:37 +01:00
This commit is contained in:
parent
e56fd449fb
commit
8fa4dc4ba8
@ -548,10 +548,11 @@ class _Pickler:
|
|||||||
self.framer.commit_frame()
|
self.framer.commit_frame()
|
||||||
|
|
||||||
# Check for persistent id (defined by a subclass)
|
# Check for persistent id (defined by a subclass)
|
||||||
pid = self.persistent_id(obj)
|
if save_persistent_id:
|
||||||
if pid is not None and save_persistent_id:
|
pid = self.persistent_id(obj)
|
||||||
self.save_pers(pid)
|
if pid is not None:
|
||||||
return
|
self.save_pers(pid)
|
||||||
|
return
|
||||||
|
|
||||||
# Check the memo
|
# Check the memo
|
||||||
x = self.memo.get(id(obj))
|
x = self.memo.get(id(obj))
|
||||||
|
@ -224,25 +224,31 @@ class PyIdPersPicklerTests(AbstractIdentityPersistentPicklerTests,
|
|||||||
def test_pickler_super(self):
|
def test_pickler_super(self):
|
||||||
class PersPickler(self.pickler):
|
class PersPickler(self.pickler):
|
||||||
def persistent_id(subself, obj):
|
def persistent_id(subself, obj):
|
||||||
|
called.append(obj)
|
||||||
self.assertIsNone(super().persistent_id(obj))
|
self.assertIsNone(super().persistent_id(obj))
|
||||||
return obj
|
return obj
|
||||||
|
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
f = io.BytesIO()
|
f = io.BytesIO()
|
||||||
pickler = PersPickler(f, proto)
|
pickler = PersPickler(f, proto)
|
||||||
|
called = []
|
||||||
pickler.dump('abc')
|
pickler.dump('abc')
|
||||||
|
self.assertEqual(called, ['abc'])
|
||||||
self.assertEqual(self.loads(f.getvalue()), 'abc')
|
self.assertEqual(self.loads(f.getvalue()), 'abc')
|
||||||
|
|
||||||
def test_unpickler_super(self):
|
def test_unpickler_super(self):
|
||||||
class PersUnpickler(self.unpickler):
|
class PersUnpickler(self.unpickler):
|
||||||
def persistent_load(subself, pid):
|
def persistent_load(subself, pid):
|
||||||
|
called.append(pid)
|
||||||
with self.assertRaises(self.persistent_load_error):
|
with self.assertRaises(self.persistent_load_error):
|
||||||
super().persistent_load(pid)
|
super().persistent_load(pid)
|
||||||
return pid
|
return pid
|
||||||
|
|
||||||
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
for proto in range(pickle.HIGHEST_PROTOCOL + 1):
|
||||||
unpickler = PersUnpickler(io.BytesIO(self.dumps('abc', proto)))
|
unpickler = PersUnpickler(io.BytesIO(self.dumps('abc', proto)))
|
||||||
|
called = []
|
||||||
self.assertEqual(unpickler.load(), 'abc')
|
self.assertEqual(unpickler.load(), 'abc')
|
||||||
|
self.assertEqual(called, ['abc'])
|
||||||
|
|
||||||
class PyPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests, unittest.TestCase):
|
class PyPicklerUnpicklerObjectTests(AbstractPicklerUnpicklerObjectTests, unittest.TestCase):
|
||||||
|
|
||||||
|
@ -0,0 +1,3 @@
|
|||||||
|
The Python implementation of :mod:`pickle` no longer calls
|
||||||
|
:meth:`pickle.Pickler.persistent_id` for the result of
|
||||||
|
:meth:`!persistent_id`.
|
Loading…
Reference in New Issue
Block a user