https://github.com/python/cpython/commit/a19832bfbffcca0c224434a877f671137bc87137
commit: a19832bfbffcca0c224434a877f671137bc87137
branch: 3.12
author: Serhiy Storchaka <[email protected]>
committer: serhiy-storchaka <[email protected]>
date: 2024-11-06T21:11:37Z
summary:

[3.12] gh-126489: Do not call persistent_id() for a persistent id in Python 
pickle (GH-126490) (GH-126516)

(cherry picked from commit 8fa4dc4ba8646c59f945f2451c53e2919f066065)

files:
A Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst
M Lib/pickle.py

diff --git a/Lib/pickle.py b/Lib/pickle.py
index 01c1a102794d57..ea5f1c5dc36c91 100644
--- a/Lib/pickle.py
+++ b/Lib/pickle.py
@@ -533,10 +533,11 @@ def save(self, obj, save_persistent_id=True):
         self.framer.commit_frame()
 
         # Check for persistent id (defined by a subclass)
-        pid = self.persistent_id(obj)
-        if pid is not None and save_persistent_id:
-            self.save_pers(pid)
-            return
+        if save_persistent_id:
+            pid = self.persistent_id(obj)
+            if pid is not None:
+                self.save_pers(pid)
+                return
 
         # Check the memo
         x = self.memo.get(id(obj))
diff --git 
a/Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst 
b/Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst
new file mode 100644
index 00000000000000..8a6573cdea7b42
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2024-11-06-13-41-38.gh-issue-126489.toaf-0.rst
@@ -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`.

_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]

Reply via email to