Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Python > Method chaining on decorator got SyntaxError

Reply
Thread Tools

Method chaining on decorator got SyntaxError

 
 
Makoto Kuwata
Guest
Posts: n/a
 
      02-16-2011
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.

--
regards,
makoto kuwata
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Why doesnt __getattr__ with decorator dont call __get_method in decorator glomde Python 5 03-29-2007 02:48 PM
Retaining *this in method chaining Ashwin Nanjappa C++ 6 02-01-2007 08:59 AM
Method chaining for instance methods that return void Dmytro Sheyko Java 3 01-19-2006 02:32 PM
Method chaining with generics iksrazal@terra.com.br Java 30 09-06-2005 12:47 AM
Method Chaining Issues aartist Ruby 25 06-03-2005 12:45 AM



Advertisments
 



1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57