Method chaining on decorator got SyntaxError

alex23 wuwei23 at
Thu Feb 17 04:56:41 CET 2011

Makoto Kuwata <k... at> wrote:
> I'm sad about this restriction because:
>     @recipe.product('*.html').ingreds('$(1).rst')
>     def file_html(c):
>         # do something
> is enough simple and more readable than:
>     @recipe.product('*.html')
>     @recipe.ingreds('$(1).rst')
>     def file_html(c):
>         # do something
> But I'll follow the Python's philosophy.

Personally, I'd find this approach a lot clearer:

rst2html = recipe.product('*.html').ingred('$(1).rst')

def file_html(c):
   # etc

It allows for easier reuse of your decorators and it labels it in a
way that I can understand from the name as opposed to having to
decipher the decorator method chain to work out its intent.

More information about the Python-list mailing list