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

Guido van Rossum guido at python.org
Tue Nov 27 05:28:11 CET 2007


On Nov 26, 2007 3:49 PM, Greg Ewing <greg.ewing at canterbury.ac.nz> wrote:
> Nick Coghlan wrote:
> > 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.
>
> A builtin method descriptor is the C equivalent of a
> function object, not an instancemethod.

Not quite -- it holds a reference to an object too.

> The desired behaviour would be for builtin method
> descriptors to have a __get__ method that creates
> an instancemethod object, like functions do.

They have that too. See:

Python 2.4.4 (#1, Oct 18 2006, 10:34:39)
[GCC 4.0.1 (Apple Computer, Inc. build 5341)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>> a = []
>>> f = list.append
>>> f
<method 'append' of 'list' objects>
>>> g = f.__get__(a)
>>> g
<built-in method append of list object at 0x590f8>
>>> a.append
<built-in method append of list object at 0x590f8>
>>> g(42)
>>> a
[42]
>>>

What am I missing?

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


More information about the Python-3000 mailing list