[Python-3000] Unbound methods -- keep creating API?
Guido van Rossum
guido at python.org
Tue Nov 27 19:29:19 CET 2007
On Nov 27, 2007 2:16 AM, Nick Coghlan <ncoghlan at gmail.com> wrote:
> 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)
> >>> type(map)
> <type 'builtin_function_or_method'>
> >>> '__get__' in dir(map)
> This seems like an eminently sensible idea to me, and not really
> something that can be done in the 2.x series.
On second thought (after responding to Greg), I agree that it is
sensible. But why can't it be done in 2.6?
The attached implementation is simple enough...
--Guido van Rossum (home page: http://www.python.org/~guido/)
-------------- next part --------------
A non-text attachment was scrubbed...
Size: 831 bytes
Desc: not available
Url : http://mail.python.org/pipermail/python-3000/attachments/20071127/ef3ca9b7/attachment.bin
More information about the Python-3000