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 belopolsky
Recipients belopolsky, exarkun
Date 2010-08-01.23:55:15
SpamBayes Score 6.704071e-07
Marked as misclassified No
Message-id <1280706918.57.0.413587286562.issue9276@psf.upfronthosting.co.za>
In-reply-to
Content
Not a proposed solution, but food for thought.  Methods do have __reduce_ex__ method which works with protocol 3:

>>> class X:
...   def f(self):
...      pass

>>> X.f.__reduce_ex__(3)
(<function __newobj__ at 0x100579288>, (<class 'function'>,), {}, None, None)

This result is useless for several reasons:

1.  <class 'function'> cannot be pickled because although it's name suggests a builtin, it is only available as types.FunctionType.

2. If we define builtins.function, X.f can be pickled

>>> import builtins, types
>>> builtins.function = types.FunctionType
>>> pickle.dumps(X.f)
b'\x80\x03cbuiltins\nfunction\nq\x00)\x81q\x01}q\x02b.'

but the result is useless:

>>> pickle.loads(_)
Traceback (most recent call last):
 ..
 File "Lib/pickle.py", line 1317, in loads
    encoding=encoding, errors=errors).load()
TypeError: Required argument 'code' (pos 1) not found


I think the approach of pickling the name of the function as is done in the Twisted link above is the only reasonable one and is consistent with the way module level functions are pickled.
History
Date User Action Args
2010-08-01 23:55:18belopolskysetrecipients: + belopolsky, exarkun
2010-08-01 23:55:18belopolskysetmessageid: <1280706918.57.0.413587286562.issue9276@psf.upfronthosting.co.za>
2010-08-01 23:55:16belopolskylinkissue9276 messages
2010-08-01 23:55:15belopolskycreate