[Python-bugs-list] [ python-Feature Requests-558238 ] Pickling bound methods

noreply@sourceforge.net noreply@sourceforge.net
Mon, 20 May 2002 04:17:41 -0700


Feature Requests item #558238, was opened at 2002-05-20 11:17
You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=558238&group_id=5470

Category: Python Library
Group: None
Status: Open
Resolution: None
Priority: 5
Submitted By: Konrad Hinsen (hinsen)
Assigned to: Nobody/Anonymous (nobody)
Summary: Pickling bound methods

Initial Comment:
Last week I noticed that the pickle and cPickle modules
cannot handle bound methods. I found a solution that is
simple and (I think) general, so perhaps it should
become part of the standard library.

Here is my code:

import copy_reg

def pickle_bound_method(method):
    return getattr, (method.im_self, method.__name__)

class _Foo:
    def bar(self):
        pass

_foo = _Foo()

copy_reg.constructor(getattr)
copy_reg.pickle(type(_foo.bar), pickle_bound_method)



----------------------------------------------------------------------

You can respond by visiting: 
http://sourceforge.net/tracker/?func=detail&atid=355470&aid=558238&group_id=5470