[Python-Dev] Re: PEP 318: Decorators last before colon (original) (raw)

Casey Duncan casey at zope.com
Fri Apr 2 10:55:35 EST 2004


On Thu, 01 Apr 2004 17:25:20 -0500 David Abrahams <dave at boost-consulting.com> wrote:

Jeremy Hylton <jeremy at alum.mit.edu> writes:

> On Thu, 2004-04-01 at 07:13, Michael Hudson wrote: >> > I don't think Michel is saying they are worthless. However, the >> > proposed syntax is highly contentious. It would be good if there >> > was a short term solution that wouldn't require new syntax. That >> > would give Guido and the Python community time to figure out the >> > best syntax. >> >> We've been discussing this off and on for OVER A YEAR! If 'the >best> syntax' hasn't been figured out yet after N thousand emails on >the> subject, I see no reason to believe enlightenment is going to >arrive> soon (or ever). > > There's no particular reason to believe that effort alone will > arrive at an elegant solution. On the other hand, maybe there isn't > a good syntax for arbitrary decorators. Has something along these lines been discussed? with [staticmethod, classmethod]: def foo(x): pass def bar(x): pass IIUC, the PyObjC application needs whole swathes of functions with the same decoration, but this syntax isn't much worse for one function than for many.

What if you dropped the keyword?

[classmethod]:

  def splat(cls):
      pass

  def baz(cls):
      pass

Or how about as?

as classmethod:

 def jinkies(cls):
     pass

Which seems nice in the face of other declarations:

as protected(some_permission):

 def zoinks(self, scooby, snack):
     pass

 def jinkies(self):
     pass

or

[protected_by(some_permission)]:

  def dangerous(self, risk):
      pass

At least then the ambiguity is gone wrt unassigned lists before defs (and I won't have to rewrite all that code where I'm using list comprehensions as docs before method defs ;^). Also the grouping seems useful.

OTOH, madatory bracketing seems unpythonic to me, which makes as/with option (without mandatory brackets) seem compelling.

-Casey



More information about the Python-Dev mailing list