[Python-3000] Unbound methods -- keep creating API?

Nick Coghlan ncoghlan at gmail.com
Mon Nov 26 23:53:23 CET 2007


Christian Heimes wrote:
> Greg Ewing wrote:
>> This needs consideration. Pyrex currently makes use of
>> this behaviour when defining a Python class having Pyrex
>> functions as methods.
>>
>> However, a better solution for Pyrex would be to add
>> method-binding behaviour to the C function object, so
>> that C functions can be used directly as methods. The
>> above example would then work simply by doing
>>
>>    Example.id = id
> 
> A C function binder is very easy to implement.

True, but it would probably make more sense to find a way to let Pyrex 
re-use the method descriptor already used for builtin types:

 >>> type(str.lower)
<type 'method_descriptor'>

Interestly, I just discovered that method descriptors for builtins don't 
define im_class, im_self or im_func. I never knew that - I thought they 
had the same interface as instance methods.

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list