[Python-Dev] Re: Call for defense of @decorators (original) (raw)

Shalabh Chaturvedi shalabh at cafepy.com
Fri Aug 6 01:32:46 CEST 2004


I converted some code which makes good use decorators (an example follows):

@paramnames(username='Username', password='Password')
@webmethod(username=str, password=str)
def login(self, username, password, return_to=None):
    request = current.request
    ...

Here is some usability feedback:

The only downside I found was:

Also, this symptom might get alleviated once editors know how to color decorators nicely. An alternative character (as others have suggested) might be good too. If so, I found '|' particularly nice :)

|paramnames(username='Username', password='Password')
|webmethod(username=str, password=str)
def login(self, username, password, return_to=None):
    request = current.request
    ...

|webmethod()
def logout(self, return_to=None):
    current.request.session.user = None
    return current.request.redirect(return_to or self._q_location)

Appears accentuated, yet clean, specially for simple/single decorators. Gives an appearance that the decorators are 'connected' to the function.

Conclusion: as a user I'm +1 on the @-decorator syntax, or any similar syntax using an alternative character.

Cheers, Shalabh



More information about the Python-Dev mailing list