[Python-Dev] method decorators (PEP 318)

Greg Ewing greg at cosc.canterbury.ac.nz
Sun Mar 28 22:07:24 EST 2004


Guido:

> (1) Put decorators of the first category early in the def statement,
>     for example here:
> 
>     def foobar [classmethod] (cls, foo, bar):
>         ...
> 
> (2) Invent some other notation for setting function attributes as part
>     of the function *body*, before the doc string even.

I wouldn't mind (2) if it's done nicely enough, but I don't like
(1). I'm still strongly against putting anything between the function
name and the arglist.

> I find the mark-up in your example about the worst possible mark-up;
> in practice, these things can get quite voluminous

Something about the idea of functions having voluminous amounts of
metadata disturbs me, especially for small functions. I don't want to
have to wade through a dozen lines of metadata to get to a few lines
of actual code that tells me what the function does.

Docstrings can be quit large, but they don't seem to lead to this
problem, probably because they look quite different from code. The
proposed metadata syntaxes are going to be quite hard to distinguish
from code at first glance.

If using large amounts of metadata becomes fashionable, I think it
will be important for editors to be able to recognise it easily and
display it in a different colour.

> (For those worried that the function attribute sets appear to belong
> to the body, I point to the precedent of the docstring.  IMO the start
> of the function body is a perfectly fine place for metadata about a
> function.)

But docstrings are constants, so there are no evaluation-time or
scope issues.

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