Static method and class method comments

Markus Schaber markus at schabi.de
Thu Aug 2 09:29:12 EDT 2001


Hi,

Duncan Booth <duncan at NOSPAMrcp.co.uk> schrub:

>> Agree strongly. This will also be a problem for documentation
>> generation tools, type extraction tools and class browsers. I believe
>> it would be easy to add a contextual keyword
>> 
>>> class C:
>>>         def static foo(x, y): print "classmethod", x, y
>> 
>> 
> Not a keyword. You could just make it an optional identifier.
> If you change the existing grammar:
>    funcdef:        "def" funcname "(" [parameter_list] ")" ":" suite
> to:
>    funcdef: "def" [funcmodifier] funcname "(" [parameter_list] ")" ":"
> suite
>    funcmodifier: identifier

This idea looks good in my eyes.
 
> And make it that if a funcmodifier is present, then funcname is set to
> the result of calling funcmodifier on the function.
> 
> then you get:
>    def classmethod foo(x, y):
>       print "classmethod", x, y
> 
> but you also get the flexibility to write your own modifiers:
> 
>    def protected(fn): return protectionwrapper(fn)
>    def protected foo(x, y): pass

And it seems rather powerful for a lot of cases. But it raises the 
question what to do with combining more than one funcmodifier...

My first suggestion for an easy classmethod syntax would be to just let 
the programmer omit the self parameter, thus a class method definition 
would look like this:

class A:
  def show( , a, b, c):
    print "Class A prints",a,b,c

markus
-- 
Defend democrathy and freedom!



More information about the Python-list mailing list