Idea about method parameters

Markus Schaber markus at schabi.de
Mon Sep 24 18:49:43 EDT 2001


Chris Barker <chrishbarker at home.net> schrub:

> Markus Schaber wrote:
> 
>> Now I'd love to have the possibility to shorten this by typing:
>> 
>> class A:
>>     def m(self, self.value):
>>         pass # or the other work to be done
> 
> I suspect that this will clash with the internals somewhere, but I
> love it!

This is why I gave the following semantic definition:

class A:
    def m(self, value):
        self.value = value
        del value
        #the other work here

This is completely valid python semantics, at least since 1.5.2 (if I 
got it correctly), and it may even be implemented as a preprocessor 
like mechanism during testing / as a first step: 

Parse the parameter list from left to right, beginning with the second 
parameter. Whenever you get to a parameter that has a dot in it, and 
the part before the dot equals to the first (self per convention) 
parameter (or the class name or a superclass name), replace the 
parameter with the part of the right side of the dot (keeping an 
eventual default value declaration which begins with =). Then insert 
the assignment and the del statement after the def: statement (just 
after other generated assignments to keep the left-to-right order, but 
before any user specified code). 

markus
-- 
"The strength of the Constitution lies entirely in the determination of 
each citizen to defend it. Only if every single citizen feels duty 
bound to do his share in this defense are the constitutional rights 
secure." -- Albert Einstein



More information about the Python-list mailing list