pickle docs - what can be pickled

In the pickle docs of 3.3, section 12.4.1 says: "instances of such classes whose __dict__ or __setstate__() is picklable" Does it actually mean __setstate__ or __getstate__ ? Eli

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01/01/2013 01:28 AM, Eli Bendersky wrote:
In the pickle docs of 3.3, section 12.4.1 says:
"instances of such classes whose __dict__ or __setstate__() is picklable"
Does it actually mean __setstate__ or __getstate__ ?
ISTM __setstate__ is correct, since that's the method that has to be looked up at unpickling time. (__getstate__ is called at pickling time.) Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlDi/EYACgkQN9GcIYhpnLBGEQCeOU8jsEDj0nKLNxcc/Z0LQRNM k5QAnikcfb72aQ8LjEno0njjhh5JuPuO =BXY+ -----END PGP SIGNATURE-----

On Tue, Jan 1, 2013 at 7:09 AM, Georg Brandl <georg@python.org> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 01/01/2013 01:28 AM, Eli Bendersky wrote:
In the pickle docs of 3.3, section 12.4.1 says:
"instances of such classes whose __dict__ or __setstate__() is picklable"
Does it actually mean __setstate__ or __getstate__ ?
ISTM __setstate__ is correct, since that's the method that has to be looked up at unpickling time. (__getstate__ is called at pickling time.)
Yes, __getstate__ is called at pickling time, which is precisely why it should replace __setstate__ in the quoted statement, IMHO. Note that the doc of __getstate__ says: "Classes can further influence how their instances are pickled; if the class defines the method __getstate__()<http://docs.python.org/dev/library/pickle.html?highlight=pickle#pickle.objec...>, it is called and the returned object is pickled as the contents for the instance, instead of the contents of the instance’s dictionary. If the __getstate__()<http://docs.python.org/dev/library/pickle.html?highlight=pickle#pickle.object.__getstate__>method is absent, the instance’s __dict__ <http://docs.python.org/dev/library/stdtypes.html#object.__dict__>is pickled as usual." Which further suggest that __getstate__ and __dict__ are, in a sense, interchangeable. Eli

-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1 On 01/01/2013 04:37 PM, Eli Bendersky wrote:
On Tue, Jan 1, 2013 at 7:09 AM, Georg Brandl <georg@python.org <mailto:georg@python.org>> wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
On 01/01/2013 01:28 AM, Eli Bendersky wrote:
In the pickle docs of 3.3, section 12.4.1 says:
"instances of such classes whose __dict__ or __setstate__() is picklable"
Does it actually mean __setstate__ or __getstate__ ?
ISTM __setstate__ is correct, since that's the method that has to be looked up at unpickling time. (__getstate__ is called at pickling time.)
Yes, __getstate__ is called at pickling time, which is precisely why it should replace __setstate__ in the quoted statement, IMHO. Note that the doc of __getstate__ says:
You're right. To be clear, the docs should talk about "whose __dict__ or the result of calling __getstate__() can be pickled". Georg -----BEGIN PGP SIGNATURE----- Version: GnuPG v2.0.19 (GNU/Linux) iEYEARECAAYFAlDjBpkACgkQN9GcIYhpnLDIBwCdFN3gQAkSQVi2a2UxYpgslq5V 378AoI/mcpAQxvkCiR3CdGBbRBVXAOPQ =2PyJ -----END PGP SIGNATURE-----
participants (2)
-
Eli Bendersky
-
Georg Brandl