Python decorator syntax limitations

Lie Ryan lie.1296 at
Mon Jan 18 18:25:11 CET 2010

On 01/19/10 03:44, Jonathan S wrote:
> Any suggestions? I have my reasons for doing this, (news_page is a
> class, and __call__ is used to wrap the template.)
> I'm sure this is a limitation in the syntax, but would parenthesis
> somewhere help?

The restriction[1] is put in there since Guido has a "gut feeling" that
allowing arbitrary expression in decorator syntax severely harms

A workaround is to put an assignment above it:

nplookup = news_page('template.html').lookup
@nplookup(News, 'news_id', 'news')
def view(request, group, news):

If you are sure you can put up a convincing argument for lifting this
restriction, and you are willing to put some time arguing, you are
welcome to start a thread in the python-dev mailing list. Be sure to
read about previous discussions, as repeating arguments wouldn't change

[1] there is a subtle difference between "restriction" and "limitation"

More information about the Python-list mailing list