Static method and class method comments

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Jul 26 05:22:21 EDT 2001


Paul Prescod <paulp at ActiveState.com> wrote in 
news:mailman.996103958.4468.python-list at python.org:

> 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

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

-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?



More information about the Python-list mailing list