From 63ba350474d95996b33c98995ed8d05b3638bb5c Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:02:36 +0200 Subject: [PATCH 1/2] Clarify `__reduce__()` behavior when a string is returned --- Doc/library/pickle.rst | 5 ++++- 1 file changed, 4 insertions(+), 1 deletion(-) diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst index f8975c2f4281d4..d0b1c14723ad26 100644 --- a/Doc/library/pickle.rst +++ b/Doc/library/pickle.rst @@ -693,7 +693,10 @@ or both. If a string is returned, the string should be interpreted as the name of a global variable. It should be the object's local name relative to its module; the pickle module searches the module namespace to determine the - object's module. This behaviour is typically useful for singletons. + object's module: for a given ``obj`` to be pickled, the ``__module__`` + attribute is looked up on ``obj`` directly, which falls back to a lookup + on the type of ``obj`` if no ``__module__`` instance attribute is set. + This behaviour is typically useful for singletons. When a tuple is returned, it must be between two and six items long. Optional items can either be omitted, or ``None`` can be provided as their From 37851dd9aa272880850ce025896eef7f241ca6e2 Mon Sep 17 00:00:00 2001 From: Viicos <65306057+Viicos@users.noreply.github.com> Date: Fri, 17 Apr 2026 11:03:02 +0200 Subject: [PATCH 2/2] Remove outdated pickle limitation --- Doc/library/pickle.rst | 4 +--- 1 file changed, 1 insertion(+), 3 deletions(-) diff --git a/Doc/library/pickle.rst b/Doc/library/pickle.rst index d0b1c14723ad26..e2b7fcd59a8458 100644 --- a/Doc/library/pickle.rst +++ b/Doc/library/pickle.rst @@ -54,9 +54,7 @@ files. The :mod:`!pickle` module differs from :mod:`marshal` in several significant ways: * :mod:`marshal` cannot be used to serialize user-defined classes and their - instances. :mod:`!pickle` can save and restore class instances transparently, - however the class definition must be importable and live in the same module as - when the object was stored. + instances. :mod:`!pickle` can save and restore class instances transparently. * The :mod:`marshal` serialization format is not guaranteed to be portable across Python versions. Because its primary job in life is to support