Alternative decorator syntax - keyword choice

Michael Sparks zathras at thwackety.com
Sun Aug 22 11:45:22 EDT 2004


Colin J. Williams wrote:
...
> Three issues which have not been discussed much are:
>      1. the purpose of the docstring in J2 preceding the funcdef.  It it
>         to describe the transformers or the function?

I'm not sure I understand this - the implementation as is doesn't make any
changes to the position of the docstring. In some examples I've put:

# Bla
# Bla
decorate:
   staticmethod
def foo(bar):
   "rhubarb"
   pass

Largely because some doc generators currently take code like:
# Bla
# Bla
def foo(bar):
   "rhubarb"
   pass

And concatenate the "Bla Bla" docs with the "rhubarb" docs. The
location/meaning of the docstring itself is left unchanged.

>      2. the placement of the extra code relative to the funcdef.
>         (incidentally, I don't find docstring in the Python grammar)

The docstring isn't handled by the grammar - it's "manually" yanked out the
codeblock during compilation. ie it's based on the semantics of codeblocks
rather than purely the syntax. I suspect that this is the key reason why
putting the extra code inside the function's code block was ruled out.

>      3. whether the PEP 318 processes are to apply to classes as well
>         as functions.

The code/grammar tend to suggest not. The implementation I've done for J2 is
really syntactic sugar on top so the semantics aren't changed from 2.4a2.
(The simplest way of testing these things really is to take the easy way
out - download, build and play :)

Regards,


Michael.




More information about the Python-list mailing list