[Python-Dev] @-after-def-before-colon (was Re: def ... decorate) (original) (raw)

Phillip J. Eby pje at telecommunity.com
Fri Aug 13 20:26:14 CEST 2004


At 07:52 PM 8/13/04 +0200, Werner Schiendl wrote:

was the following suggested already? (don't think so):

def pstatementexpr(self, p): staticmethod grammarrule('statement : expression') version("Added in 2.4") deprecatedmethod type(None) body: """docstring here""" print p[1]

hmmmm.... that's really not much different from:

def p_statement_expr(self, p) [
    staticmethod,
    grammarrule('statement : expression'),
    version("Added in 2.4"),
    returns(None)
]:
    """Docstring"""
    body

is it?

But then, how about this:

def p_statement_expr(self, p)
    @staticmethod
    @grammarrule('statement : expression')
    @version("Added in 2.4")
    @returns(None)
as:
    """Docstring"""
    body

The decorators are much more visible with the @ signs. Also, we could possibly allow the docstring to appear in the def statement, rather than in the body, e.g.:

def p_statement_expr(self, p)
    @staticmethod
    @grammarrule('statement : expression')
    @version("Added in 2.4")
    @returns(None)
    """Docstring"""
as:
    body

Some advantages:

Disadvantages:

In other words, should indent and one-decorator-per-line be enforced?



More information about the Python-Dev mailing list