Skip to content

Commit 729c856

Browse files
[3.12] pythongh-126489: Do not call persistent_id() for a persistent id in Python pickle (pythonGH-126490)
(cherry picked from commit 8fa4dc4) Co-authored-by: Serhiy Storchaka <[email protected]>
1 parent 97ab3cf commit 729c856

File tree

2 files changed

+8
-4
lines changed

2 files changed

+8
-4
lines changed

Lib/pickle.py

+5-4
Original file line numberDiff line numberDiff line change
@@ -533,10 +533,11 @@ def save(self, obj, save_persistent_id=True):
533533
self.framer.commit_frame()
534534

535535
# Check for persistent id (defined by a subclass)
536-
pid = self.persistent_id(obj)
537-
if pid is not None and save_persistent_id:
538-
self.save_pers(pid)
539-
return
536+
if save_persistent_id:
537+
pid = self.persistent_id(obj)
538+
if pid is not None:
539+
self.save_pers(pid)
540+
return
540541

541542
# Check the memo
542543
x = self.memo.get(id(obj))
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
The Python implementation of :mod:`pickle` no longer calls
2+
:meth:`pickle.Pickler.persistent_id` for the result of
3+
:meth:`!persistent_id`.

0 commit comments

Comments
 (0)