Guido's new method definition idea

Steven D'Aprano steve at REMOVE-THIS-cybersource.com.au
Sat Dec 6 06:36:32 CET 2008


On Fri, 05 Dec 2008 20:35:07 -0800, James Stroud wrote:

> Daniel Fetchinson wrote:
>> http://neopythonic.blogspot.com/2008/10/why-explicit-self-has-to-
stay.html
>> 
>> The proposal is to allow this:
>> 
>> class C:
>>     def self.method( arg ):
>>         self.value = arg
>>         return self.value
>> 
>> instead of this:
>> 
>> class C:
>>     def method( self, arg ):
>>         self.value = arg
>>         return self.value
> 
>> I'd like this new way of defining methods, what do you guys think?
> 
> Consider the maverick who insists on
> 
> class C:
>    def me.method(arg):
>      self.value = arg

Replace "self" with "me".
 
> which should be equivalent to
> 
> class C:
>    def method(me, arg):
>      me.value = arg
> 
> What's the interpreter going to do with our maverick's code?

I don't see why you think this is a problem. The compiler merely treats:

    def ANYTHING.method(arg):

inside a class as if it were 

    def method(ANYTHING, arg):


and it will Just Work. If you want a classmethod, you still need to use 
the classmethod decorator -- there's no reason to make self and cls 
keywords.

Personally, I'm neutral on the idea. Perhaps +0.00001.


-- 
Steven



More information about the Python-list mailing list