[Python-Dev] method decorators (PEP 318)

Barry Warsaw barry at python.org
Sat Mar 27 00:27:33 EST 2004


On Fri, 2004-03-26 at 10:10, 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

The way I /want/ to spell this is something like:

def foobar(self, arg):
    foobar.author = 'Guido van Rossum'
    foobar.deprecated = True

I know all the practical problems with this suggestion, but to me,
that's the most natural spelling.  I suppose something like this might
also not be horrible:

def foobar [
    .author = 'Guido van Rossum'
    .deprecated = True
    classmethod
    ] (self, arg)

Naw, these probably don't mix well.  Hmm,

def foobar {
    author = 'Guido van Rossum'
    deprecated = True
    } [classmethod, spoogemethod, insanity
    ] (self, arg):
    # Now what the heck does this thing do?

Blech.

OTOH, I'm all for trying to get a more natural way of spelling function
attributes, but decorators can also do the trick in a nasty way:

def foobar [
    lambda f: f.author = 'Guido van Rossum',
    lambda f: f.deprecated = True,
    classmethod] (self, arg):
    # Now what?

It's way past my bedtime <wink> so ignore my babbling.
-Barry





More information about the Python-Dev mailing list