[Python-Dev] Suggesting '.' decorators (PEP318) (original) (raw)

Kevin J. Butler python-kbutler at sabaydi.com
Sat Aug 7 06:55:35 CEST 2004


Many people wrote: > Lots of options

I haven't seen this mentioned, so I'm going to throw in my suggestion.

The following makes sense to me, uses previously invalid syntax, and uses the '.' punctuation in a way similar to existing/proposed usage:

   def longMethodNameForEffect(longArgumentOne=None,
                               longArgumentTwo=42):
       .staticmethod
       .funcattrs(grammar="'@' dotted_name [ '(' [arglist] ')' ]",
                  status="experimental", author="BDFL")
       """
       asdfasdf
       """
       raise NotYetImplemented

If we want to allow one-liner decorators (questionable to me):

   def myMethod(self): .staticmethod
       raise NotYetImplemented

Advantages/disadvantages of positioning at start of block:

0 Perhaps decorators should be allowed before or after the docstring. If you have to choose, I'd choose making it before the docstring.

Advantages/disadvantages of .decorators:

+/0 Syntax obvious visually (Someone will complain that the leading period gets lost - that person should switch to a fixed-width font, as used when coding. <.5 wink>) Easy to highlight.

0 Although it is a punctuation-based syntax, it is compatible with existing/proposed '.' usage ('.' can mean subordination to a containing construct like 'with', and passing the implicit "func" argument is analogous to passing "self")

0 Compatible with some future "with ...:" syntax, as decorators must immediately follow a 'def ...:' (or possibly a 'class ...:'), so if there is a 'with ...:' what follows cannot be a decorator.

Misc items from the PEP applied to .decorators:

?+ Compile time (? as much as the @ syntax is?)

Public or private feedback appreciated, I will summarize private feedback to the list.

kb



More information about the Python-Dev mailing list