Re: Method chaining on decorator got SyntaxError
alex23 wuwe...@gmail.com wrote: Makoto Kuwata k...@kuwata-lab.com 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') @rst2html 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. Or another way would be to define `recipe` such that something like this works: @recipe(product='*.html', ingreds='$(1).rst') def file_html(c): ... -- Duncan Booth http://kupuguy.blogspot.com -- http://mail.python.org/mailman/listinfo/python-list
Re: Method chaining on decorator got SyntaxError
On 16/02/2011 23:25, Makoto Kuwata wrote: Hi, I have a question about decorator. I tried the following example and got Syntax Error. class deco(object): def __init__(self, name): self._name = name def foo(self, value): self._foo = value return self def __call__(self, func): func._deco = self return func ## ok @deco('aaa') def f1(): pass ## Syntax Error @deco('aaa').foo('bbb') # SyntaxError: invalid syntax def f2(): pass The above code shows that Python doesn't allow method chain on decorator syntax. Why does this limitation exist? I want to chain methods as a certain DSL, just like: @recipe().product('*.html').ingreds('$(1).rst') def file_html(c): system(c%rst2html.py $(ingred) $(product)) If you know the reason of the restriction, let me know it. You may want to read the discussion at: https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en -- http://mail.python.org/mailman/listinfo/python-list
Re: Method chaining on decorator got SyntaxError
Thank you MRAB, On Thu, Feb 17, 2011 at 8:49 AM, MRAB pyt...@mrabarnett.plus.com wrote: You may want to read the discussion at: https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en -- I can't figure out what is the point or conclusion of that discussion. Is there any technical reason? Or Ideological reason? -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
Re: Method chaining on decorator got SyntaxError
On 17/02/2011 01:55, Makoto Kuwata wrote: Thank you MRAB, On Thu, Feb 17, 2011 at 8:49 AM, MRABpyt...@mrabarnett.plus.com wrote: You may want to read the discussion at: https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en -- I can't figure out what is the point or conclusion of that discussion. Is there any technical reason? Or Ideological reason? Ideological. Keep it simple. Readability, not succinctness, is what's Pythonic. -- Mike Meyer -- http://mail.python.org/mailman/listinfo/python-list
Re: Method chaining on decorator got SyntaxError
On Thu, Feb 17, 2011 at 11:40 AM, MRAB pyt...@mrabarnett.plus.com wrote: On 17/02/2011 01:55, Makoto Kuwata wrote: Thank you MRAB, On Thu, Feb 17, 2011 at 8:49 AM, MRABpyt...@mrabarnett.plus.com wrote: You may want to read the discussion at: https://groups.google.com/group/python-ideas/browse_thread/thread/1eebf486969c39a1/?hl=en -- I can't figure out what is the point or conclusion of that discussion. Is there any technical reason? Or Ideological reason? Ideological. Keep it simple. Readability, not succinctness, is what's Pythonic. -- Mike Meyer Thank you, MRAB. 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. -- regards, makoto kuwata -- http://mail.python.org/mailman/listinfo/python-list
Re: Method chaining on decorator got SyntaxError
Makoto Kuwata k...@kuwata-lab.com 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') @rst2html 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. -- http://mail.python.org/mailman/listinfo/python-list