[Python-Dev] method decorators (PEP 318) (original) (raw)

Robert Mollitor mollitor at earthlink.net
Fri Mar 26 16:32:14 EST 2004


On Friday, March 26, 2004, at 10:10 AM, Guido van Rossum wrote:

(2) Invent some other notation for setting function attributes as part of the function body, before the doc string even.

For (2) I am thinking aloud here: def foobar(self, arg): @author: "Guido van Rossum" @deprecated pass

Ages ago I used to think there was some type of internationalization problem with '@', but I guess its use in Java, not to mention in URLs, belies that notion. Still, you might want to save that token for some future operator that can be used amongst other operators in an expression.

(Also thinking out loud) How about

def foobar (self, arg):
    :doc """This is my doc string."""
    :author "Guido van Rossum"
    :deprecated
    pass

Syntactically, I believe this could work, though you would only want it for funcdef and classdef and probably not in single-line suites. So (maybe):

def_suite: simpe_stmt | NEWLINE INDENT decoration* stmt+ DEDENT
decoration: ':' test NEWLINE

The hand waving justification is that while a ':' at the end of a line or in the middle means "here comes the good stuff", at the beginning of the line it could mean "but first here is an aside".

Robert Mollitor



More information about the Python-Dev mailing list