Python decorator syntax limitations

Jonathan S jonathan.slenders at gmail.com
Mon Jan 18 11:44:41 EST 2010


Hi all,
The following is what I want to do, but this results in a syntax
error:


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


What does work is the equivalent old way of doing decorating:


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



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?

Thanks!
Jonathan



More information about the Python-list mailing list