[Python-3000] Unbound methods -- keep creating API?
Nick Coghlan
ncoghlan at gmail.com
Tue Nov 27 11:16:59 CET 2007
Greg Ewing wrote:
> Guido van Rossum wrote:
>> They have that too. See:
>>
>>>>> f = list.append
>>>>> g = f.__get__(a)
>>>>> g
>> <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.
>
> I'm concerned with built-in function objects that
> are *not* methods of anything. 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.
I think I see what you're getting at now - adding a '__get__' method to
the basic C function wrapper that returns self when retrieved from the
class, and a bound instancemethod when retrieved from an instance.
To illustrate the difference between builtin functions and methods:
>>> type(str.lower)
<type 'method_descriptor'>
>>> '__get__' in dir(str.lower)
True
>>> type(map)
<type 'builtin_function_or_method'>
>>> '__get__' in dir(map)
False
This seems like an eminently sensible idea to me, and not really
something that can be done in the 2.x series.
Cheers,
Nick.
--
Nick Coghlan | ncoghlan at gmail.com | Brisbane, Australia
---------------------------------------------------------------
http://www.boredomandlaziness.org
More information about the Python-3000
mailing list