Decorator keyword

S

Steven Bethard

I mentioned in a previous post that I'd much prefer some sort of
keyword as a decorator indication than a character like @ (or the
recently suggested |). A promising note on python-dev:

http://mail.python.org/pipermail/python-dev/2004-August/047001.html
Perhaps this could be addressed by requiring "from __future__ import
decorators", for one release, just like was done for "yield". I
expect that this would be acceptable to the ObjC folks, too. It
wouldn't be my favorite, but I won't rule it out just because of the
new keyword (and yes, this is a softening of my position on new
keywords).

--Guido van Rossum (home page: http://www.python.org/~guido/)

I was just going to let this go because I thought it had been shut
down, but as it seems to have been reopened, I'd love to see something
like:

with classmethod
with returns(int)
def func(*args, **kwds):
return 1

Or if you don't like so many lines:

with [classmethod, returns(int)]
def func(*args, **kwds):
return 1

Or perhaps, if you like to see the def by itself:

def func(*args, **kwds) with [classmethod, returns(int)]:
return 1

Really, I'd be much happier with any of these than any of the solely
symbol-based versions. Neither [] alone after a function def or '@'
before one reads clearly to me as an indicator of decoratorhood.

I've always liked that Python tries to be human-readable (e.g. "for x
in lst" reads almost like English). If at all possible, I'd like
decorators to be the same way. In fact, while I've only used 'with'
above (because it was non-'as' keyword suggestion in the wiki), I'd be
just as happy (maybe happier) with 'decorate' or 'deco' or something
along those lines that would read even easier.

Steve
 
A

Anthony Baxter

I was just going to let this go because I thought it had been shut
down, but as it seems to have been reopened, I'd love to see something
like:

with classmethod
with returns(int)
def func(*args, **kwds):
return 1

"with" is a non-starter - there's already other plans to use with for other
things, at some distant point. Also, if we're to have a new keyword, it
should be _much_ more obvious than 'with'.
 
D

David Fraser

Anthony said:
"with" is a non-starter - there's already other plans to use with for other
things, at some distant point. Also, if we're to have a new keyword, it
should be _much_ more obvious than 'with'.

Any pointers to info on other plans for with?
suggestions: declare

declare classmethod
declare returns(int)
def func(*args, **kwds):
return 1

Other ideas would be "decorate", but this doesn't really seem to make
sense (perhaps suggesting that decorators isn't the best name for them
:)) or "wrap" (because they literally wrap the function, but again that
doesn't seem intuitive.


David
 
T

Tuure Laurinolli

David said:
Any pointers to info on other plans for with?
suggestions: declare

declare classmethod
declare returns(int)
def func(*args, **kwds):
return 1

Other ideas would be "decorate", but this doesn't really seem to make
sense (perhaps suggesting that decorators isn't the best name for them
:)) or "wrap" (because they literally wrap the function, but again that
doesn't seem intuitive.

I was trying to find some keyword that would incorporate the name
"decorator" somehow, but couldn't really find any (except decorate, of
course), thus I don't think decorator is a good name for those things.

I though "use" could be good, but the function won't really use the
functions it's decorated with, rather thay are used to describe the
function. Keyword "describe" would make the metafunctions "descriptors",
although the verb-as-keyword approach doesn't really work because the
quantifiers are between the predicate and the object(decorate with
silver and gold this tree).

Could the decorating expressions be inside the function-block?

Could there be decorating blocks inside which the function blocks would
reside?
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Staff online

Members online

Forum statistics

Threads
473,755
Messages
2,569,536
Members
45,012
Latest member
RoxanneDzm

Latest Threads

Top