Skip to content

Commit ae65e0c

Browse files
[3.13] gh-148669: Clarify __reduce__() module lookup behavior (GH-148670) (#149705)
gh-148669: Clarify `__reduce__()` module lookup behavior (GH-148670) (cherry picked from commit 54a5fd4) Co-authored-by: Victorien <65306057+Viicos@users.noreply.github.com>
1 parent 5ad22a8 commit ae65e0c

1 file changed

Lines changed: 5 additions & 2 deletions

File tree

Doc/library/pickle.rst

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -59,7 +59,7 @@ The :mod:`pickle` module differs from :mod:`marshal` in several significant ways
5959
* :mod:`marshal` cannot be used to serialize user-defined classes and their
6060
instances. :mod:`pickle` can save and restore class instances transparently,
6161
however the class definition must be importable and live in the same module as
62-
when the object was stored.
62+
when the object was pickled.
6363

6464
* The :mod:`marshal` serialization format is not guaranteed to be portable
6565
across Python versions. Because its primary job in life is to support
@@ -680,7 +680,10 @@ or both.
680680
If a string is returned, the string should be interpreted as the name of a
681681
global variable. It should be the object's local name relative to its
682682
module; the pickle module searches the module namespace to determine the
683-
object's module. This behaviour is typically useful for singletons.
683+
object's module: for a given ``obj`` to be pickled, the ``__module__``
684+
attribute is looked up on ``obj`` directly, which falls back to a lookup
685+
on the type of ``obj`` if no ``__module__`` instance attribute is set.
686+
This behaviour is typically useful for singletons.
684687

685688
When a tuple is returned, it must be between two and six items long.
686689
Optional items can either be omitted, or ``None`` can be provided as their

0 commit comments

Comments
 (0)