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

Guido van Rossum guido at python.org
Tue Nov 27 00:00:06 CET 2007


On Nov 26, 2007 2:53 PM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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.

They have, if you only consider the *important* operations. For method
descriptors the only thing you can count on is __call__. The rest are
internal implementation details -- and besides, what would you expect
im_func to be for a C function? :-)

-- 
--Guido van Rossum (home page: http://www.python.org/~guido/)


More information about the Python-3000 mailing list