[Python-Dev] 2.4a2, and @decorators (original) (raw)

Guido van Rossum guido at python.org
Tue Aug 3 03:05:15 CEST 2004


The one thing I do dislike about the new addition is the arbitrary (?) restriction on expression allowed in a decorator. From Grammar.. decorator: '@' dottedname [ '(' [arglist] ')' ] That seems quite odd to me. Is there some reason it couldn't be: decorator: '@' test ?

The first patch on SF actually had '@' test, and I requested that it be changed. Most things that are 'test' but not 'dotted_name' optionally followed by an argument list don't make sense as decorators; if you really have a need to write

@ foo or bar
def f(): ...

you can write

deco = foo or bar
@deco
def f(): ...

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



More information about the Python-Dev mailing list