Revised PEP 318 - Function/Method Decorator Syntax

Skip Montanaro skip at pobox.com
Tue Jun 10 18:10:06 EDT 2003


    >> i think the use of [] is quite logic. it's a _list_ of function
    >> decorators.  and it helps readability, at least the variants should
    >> be listed as alternatives in the PEP.

    Erik> It's a sequence.  And, if you want to get technical, it's more
    Erik> likely to be handled as a tuple internally, anyway.

I sent this off to Kevin Smith without a cc to the list.  Since some of the
recent discussion overlaps with what I sent to him I figure I might as well
let it loose here as well. 

1. If people don't like 'as', what about 'mod' (as in "modified by") or
   'with' (as in "augmented with")?  I'm happy with nothing (as long as the
   decorators are enclosed in sequence brackets of some kind), but that's
   just me.

2. I still like the [ decorator, ... ] form better.  In the
   decorators-as-tuple case I would never list the decorators without the
   surrounding parens because it's quite likely the function declaration
   would spill over onto multiple lines and the open paren would allow you
   to continue lines without a backslash.  For consistency, I'd then include
   them even if the declaration was short enough.  Then I'd be left with

       def foo(self) as (synchronized(lock), classmethod):
           perform method operation

   or worse:

       def foo(self) as (classmethod,):
           perform method operation

   (note the required trailing comma for a singleton tuple).

   The second set of parens looks vaguely like another argument list to me.
   A naive interpretation of the above might be that "self" and
   "classmethod" are somehow related.

   List constructors don't suffer from the trailing comma disease, they are
   just as helpful when lines need to be continued and they don't look as
   much like another set of function parameters as tuples do.

Skip






More information about the Python-list mailing list