[Python-3000] Unbound methods -- keep creating API?
Guido van Rossum
guido at python.org
Tue Nov 27 19:15:56 CET 2007
On Nov 26, 2007 10:43 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Guido van Rossum wrote:
> > They have that too. See:
> >>>>f = list.append
> >>>>g = f.__get__(a)
> > <built-in method append of list object at 0x590f8>
> Hmmm. It seems that C method objects are more
> like an unbound method object that's pre-bound to a
> particular class.
Yes, that's exactly what an unbound method was. While for Python
functions there's no compelling reason (from the VM's POV anyway) why
they should only be called on instances of a particular class, for
built-in functions there is a very big reason -- the C code is written
assuming a specific instance lay-out.
> I'm concerned with built-in function objects that
> are *not* methods of anything.
Like 'len', right?
> I'm suggesting they
> should behave the same way as a Python function when
> you put one in a class, i.e. accessing it through an
> instance creates a bound method.
> If that were the case, then Pyrex wouldn't have
> to do anything special to create a Python class
> containing a method implemented in Pyrex, and
> unbound method objects could cease to exist without
> causing Pyrex any problem.
Couldn't PyRex define its own type for its functions that has a
__get__ descriptor with the appropriate semantics?
--Guido van Rossum (home page: http://www.python.org/~guido/)
More information about the Python-3000