[Python-3000] The case for unbound methods?

Nick Coghlan ncoghlan at gmail.com
Sat Mar 8 09:30:12 CET 2008


Anthony Tolle wrote:
> On Thu, Mar 6, 2008 at 11:59 PM, Guido van Rossum <guido at python.org> wrote:
>> Would you mind giving an "executive summary" of your argument that
>>  doesn't require scanning 40 lines of code?
>>
> 
> Let me put it this way: if unbound methods are gone for good, then I
> think it would nice to develop some guidance on checking the signature
> of callable objects, to enable decorators to play nice with each
> other--especially if they intend to modify the argument list.

The short-short version (as PJE already summarised it) of the underlying 
problem: functools.partial style functionality doesn't always play well 
with methods, because the first argument may need special handling once 
__get__ has been invoked, but there's not always any easy way to tell if 
this is the case. With the removal of unbound methods in Py3k, there's 
no longer any reliable way at all to tell the difference between an 
unbound method and a static method.

functools.partial actually ducks the issue entirely by always creating 
an object that behaves like a static method - it has no __get__ method, 
so acts like any other class attribute rather than trying to act as a 
descriptor. The downside of this is that you can't use it to wrap an 
unbound method, since you want to insert the later supplied 'self' 
argument before the positional args rather than after.

Descriptor wrapping is actually quite a complicated topic - I think the 
original poster has a valid complaint, but I'm not sure that restoring 
unbound methods is the right answer (unfortunately, I don't have a 
better answer to offer).

Cheers,
Nick.

-- 
Nick Coghlan   |   ncoghlan at gmail.com   |   Brisbane, Australia
---------------------------------------------------------------
             http://www.boredomandlaziness.org


More information about the Python-3000 mailing list