[Python-Dev] @decorators, the PEP and the "options" out there?

Greg Ewing greg at cosc.canterbury.ac.nz
Fri Aug 6 04:07:42 CEST 2004


"Phillip J. Eby" <pje at telecommunity.com>:

> I updated the Wiki page, and added another syntax, the original "def 
> function() [decorator]:" syntax.  Interestingly, it looks like one of the 
> options with the most pluses and fewest minuses of any syntax you've listed 
> on that page; it's only ugly for long decorator definitions, and Guido said 
> he didn't care if a syntax was ugly.  :)

Moreover, it seems to me that the main use cases proposed for long
decorator expressions would be served just as well, or perhaps even
better, by a convenient way of specifying function attributes,
together with a suitable metaclass.

  def aMethodWithAnInt_andAString(self, x, y):
    @signature = "is"
    ...

To me, that seems like a more logical place to put something like a
signature for an external function interface. It's a detail of
interest to the implementor of the function, but not to its user, so
putting it above the "def" gives it too much prominence. 

Also, putting anything up there (especially something long) tends to
interfere with one's ability to scan down a list of defs looking for a
function name.

I hope Guido will see these arguments as being rational ones about
usability and not irrational ones about aesthetics. At the least,
perhaps they could be included in the PEP for posterity.

Greg Ewing, Computer Science Dept, +--------------------------------------+
University of Canterbury,	   | A citizen of NewZealandCorp, a	  |
Christchurch, New Zealand	   | wholly-owned subsidiary of USA Inc.  |
greg at cosc.canterbury.ac.nz	   +--------------------------------------+


More information about the Python-Dev mailing list