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.

Author pitrou
Recipients pitrou, sbt, vstinner
Date 2011-12-02.19:10:39
SpamBayes Score 5.551115e-17
Marked as misclassified No
Message-id <1322852729.3589.7.camel@localhost.localdomain>
In-reply-to <1322843353.56.0.297081736881.issue13520@psf.upfronthosting.co.za>
Content
> The attached patch makes pickle use an object's __qualname__ attribute
> if __name__ does not work.
> 
> This makes nested classes, unbound instance methods and static methods
> picklable (assuming that __module__ and __qualname__ give the correct
> "address").

Thanks. I'm not sure that's a good approach for protocol 3: some pickles
created by Python 3.3 would not be readable by Python 3.2. That's why I
initially added that idea to PEP 3154, for a hypothetical protocol 4.

However, perhaps it is possible to use the same reduce/getattr trick you
are proposing for instance methods?

> BTW, It would not be hard to make instance methods picklable (and, as
> a by-product, class methods) by giving instance methods a __reduce__
> method equivalent to
> 
>   def __reduce__(self):
>     return (getattr, (self.__self__, self.__name__))
> 
> Is there any reason not to make such a change?

I don't see any personally. Actually, multiprocessing has a Pickler
subclass called ForkingPickler which does something similar (in
Lib/multiprocessing/forking.py).
History
Date User Action Args
2011-12-02 19:10:40pitrousetrecipients: + pitrou, vstinner, sbt
2011-12-02 19:10:40pitroulinkissue13520 messages
2011-12-02 19:10:39pitroucreate