[Python-Dev] Unbinding of methods

Antoine Pitrou solipsis at pitrou.net
Thu Jul 19 20:54:08 CEST 2012


On Thu, 19 Jul 2012 19:53:27 +0300
M Stefan <mstefanro at gmail.com> wrote:
> Hey,
> 
> As part of pickle4, I found it interesting to add the possibility
> of pickling bound functions (instance methods). This is done by
> pickling f.__self__ and f.__func__ separately, and then adding
> a BIND opcode to tie them together.

Instead of a specific opcode, can't you use a suitable __reduce__ magic
(or __getnewargs__, perhaps)? We want to limit the number of opcodes
except for performance-critical types (and I don't think bound methods
are performance-critical for the purpose of serialization).

> I have created a patch at [1], which adds __func__ to some other
> function types, as well as:
>   1) adds AllFunctionTypes etc. to Lib/types.py
>   2) inspect.isanyfunction(), inspect.isanyboundfunction(),
>      inspect.isanyunboundfunction()
>   3) functools.unbind

That sounds like a lot of changes if the goal is simply to make those
types picklable.

Regards

Antoine.


-- 
Software development and contracting: http://pro.pitrou.net




More information about the Python-Dev mailing list