Static method and class method comments

Kevin Smith Kevin.Smith at themorgue.org
Thu Jul 26 11:06:35 EDT 2001


In article <Xns90EA6710921D8duncanrcpcouk at 127.0.0.1>, duncan at rcp.co.uk wrote:
>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
>

I really like this idea.  This is better than the current implementation and 
the Jack Jansen syntax (which I found mildly confusing).  It also allows the 
current classmethod()/staticmethod() built-ins to still be used, but in a more 
appropriate spot in the method definition.  I can see a lot of additional 
power and flexibility with this idea.  This one gets my vote!

Kevin Smith




More information about the Python-list mailing list