Alternative decorator syntax decision

Michael Sparks zathras at thwackety.com
Fri Aug 20 20:37:11 CEST 2004


On Fri, 20 Aug 2004, Robert Brewer wrote:

> Top-posting-to-help-quick-scanning: J2 J2 J2.
>
> To Paul, M. Sparks, et al: Since J2 is coming up frequently (and Guido
> did not immediately reject it when asked), I'm going to follow through
> and try to write a proposal this weekend for J2. I'll post it here for
> feedback (and of course, wait for the 'final' count of votes) before
> posting it on py-dev.

That's very much appreciated - thank you.

Aside from what keyword (which is more sugar than anything else), the
question of ordering of semantics springs to mind. The current
implementation is little more than syntactic sugar over the current
decorator code. This means that the following three examples have the
same meaning:

@generator
@staticmethod
def tokenise(stream):
   for t in stream:
      Yield(t)

decorate:
   generator
   staticmethod
def tokenise(stream):
   for t in stream:
      Yield(t)

def tokenise(stream):
   for t in stream:
      Yield(t)
tokenise=generator(staticmethod(tokenise))

Unless it's been done to death for the more verbose option, it MIGHT be
worth asking the question as to whether it might be more appropriate
to have the following 3 meaning the same thing:

@generator
@staticmethod
def tokenise(stream):
   for t in stream:
      Yield(t)

decorate:
   staticmethod
   generator
def tokenise(stream):
   for t in stream:
      Yield(t)

def tokenise(stream):
   for t in stream:
      Yield(t)
tokenise=generator(staticmethod(tokenise))

I say might for 2 reasons 1) looking at recent posts it looks like the
current order has had a lot of thought going into it 2) recent discussion
suggests this isn't trivial to get 100% right!

I'll leave the decision as to whether to include that up to you.

Once again thanks - I'll look at sorting out the (hopefully) minor
scoping issue with the current implementation.

Best Regards,


Michael.




More information about the Python-list mailing list