compromise? keywords for static/class, move decorators to top of function

Doug Holton insert at spam.here
Fri Aug 6 13:54:45 EDT 2004


First let me say please see the wiki page about python decorators if you 
haven't already: http://www.python.org/cgi-bin/moinmoin/PythonDecorators

I propose (and others have) that built-in features have keyword support, 
like static and class methods.  Also, I believe it is more readable if 
decorators, especially longer ones, are moved to the top of the function 
body, just like docstrings, instead of coming before the function is 
even declared.  Whether you use @ or [] is still open.

def classmethod getratio (arg1, arg2):
     @accepts(int,int)
     @returns(float)
     ...

def classmethod getratio (arg1, arg2):
     [accepts(int,int), returns(float)]
     ...

This has these advantages: the function declaration itself is still the 
first and most important thing, decorators are indented just like the 
body of the function so it is more clearly a part of the function.

In the future though, if you add an "as" keyword for adapters, you could 
just say:

def classmethod getratio (arg1 as int, arg2 as int) as float:
     ...

contrast that simple example with this, which is kind of ugly:

@accepts(int,int)
@returns(float)
@classmethod #has to be last in order?
def getratio (arg1, arg2):
     ...



More information about the Python-list mailing list