This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: random.Random implements __getstate__() and __reduce__()
Type: enhancement Stage:
Components: Library (Lib) Versions: Python 3.4
process
Status: closed Resolution: wont fix
Dependencies: Superseder:
Assigned To: rhettinger Nosy List: Ramchandra Apte, mark.dickinson, python-dev, rhettinger, vterron
Priority: low Keywords:

Created on 2013-03-20 01:49 by vterron, last changed 2022-04-11 14:57 by admin. This issue is now closed.

Files
File name Uploaded Description Edit
issue17489_example.py vterron, 2013-03-20 21:27
Messages (5)
msg184721 - (view) Author: Víctor Terrón (vterron) * Date: 2013-03-20 01:49
The random.Random class implements both the __getstate__() and __reduce__() methods. My knowledge of the pickle module is very limited, but apparently this causes __getstate__() never to get called. Maybe this is a remnant from earlier code, or are both methods actually needed?
msg184746 - (view) Author: Ramchandra Apte (Ramchandra Apte) * Date: 2013-03-20 09:29
__getstate__ is for pickling instances [0], __reduce__ is for pickling the object itself [1]

^0 http://docs.python.org/2/library/pickle.html#object.__getstate__
^1 http://docs.python.org/2/library/pickle.html#object.__reduce__
msg184800 - (view) Author: Víctor Terrón (vterron) * Date: 2013-03-20 21:27
Ramchandra, that is not the behavior that I am able to reproduce. Please see the attached example: in the presence of __reduce__(), __getstate__() is not being called whether the class or an instance its pickled. This is also in consonance with what is stated in the docs, which warn that "Although powerful, implementing __reduce__() directly in your classes is error prone. For this reason, class designers should use the high-level interface (i.e., __getnewargs__(), __getstate__() and __setstate__()) whenever possible".
msg184867 - (view) Author: Raymond Hettinger (rhettinger) * (Python committer) Date: 2013-03-21 12:37
Possibly __getstate__ could be removed.  That said, I would feel a sense of risk in taking it out -- that method has been present for a *very* long time who knows what might rely on it being there.
msg185850 - (view) Author: Roundup Robot (python-dev) (Python triager) Date: 2013-04-02 17:13
New changeset 68ed5b2ca867 by R David Murray in branch 'default':
#17489: Add explanatory comment that __getstate__ is not called.
http://hg.python.org/cpython/rev/68ed5b2ca867
History
Date User Action Args
2022-04-11 14:57:43adminsetgithub: 61691
2013-04-02 17:13:29python-devsetnosy: + python-dev
messages: + msg185850
2013-03-23 13:49:35rhettingersetstatus: open -> closed
resolution: wont fix
2013-03-21 12:37:39rhettingersetpriority: normal -> low

messages: + msg184867
2013-03-21 03:36:13rhettingersetassignee: rhettinger
2013-03-20 21:27:10vterronsetfiles: + issue17489_example.py

messages: + msg184800
2013-03-20 09:29:43Ramchandra Aptesetnosy: + Ramchandra Apte
messages: + msg184746
2013-03-20 01:49:12vterroncreate