Skip to content

Commit 54a5fd4

Browse files
authored
gh-148669: Clarify __reduce__() module lookup behavior (#148670)
1 parent 7a4c6df commit 54a5fd4

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
@@ -56,7 +56,7 @@ The :mod:`!pickle` module differs from :mod:`marshal` in several significant way
5656
* :mod:`marshal` cannot be used to serialize user-defined classes and their
5757
instances. :mod:`!pickle` can save and restore class instances transparently,
5858
however the class definition must be importable and live in the same module as
59-
when the object was stored.
59+
when the object was pickled.
6060

6161
* The :mod:`marshal` serialization format is not guaranteed to be portable
6262
across Python versions. Because its primary job in life is to support
@@ -693,7 +693,10 @@ or both.
693693
If a string is returned, the string should be interpreted as the name of a
694694
global variable. It should be the object's local name relative to its
695695
module; the pickle module searches the module namespace to determine the
696-
object's module. This behaviour is typically useful for singletons.
696+
object's module: for a given ``obj`` to be pickled, the ``__module__``
697+
attribute is looked up on ``obj`` directly, which falls back to a lookup
698+
on the type of ``obj`` if no ``__module__`` instance attribute is set.
699+
This behaviour is typically useful for singletons.
697700

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

0 commit comments

Comments
 (0)