Will there be Function/class decorators in Python 2.4??

David Fraser davidf at sjsoft.com
Tue Jun 1 05:12:03 EDT 2004


Iwan van der Kleyn wrote:
> Anthony Baxter wrote:
> 
>>     the first alpha of Python 2.4 is about a month away. 
> 
> 
> Anyone know whether 2.4 will include function/class decorators?
> 
> http://python.fyxm.net/peps/pep-0320.html - Python 2.4 Release Schedule
> http://python.fyxm.net/peps/pep-0318.html - Decorators for Functions, 
> Methods and Classes
> http://shattered.teched.net/www.python.org/peps/pep-0318.html - 
> Function/Method Decorator Syntax
> 
> Basically, when I try to explain to other developers how you have to 
> define a property or class method in  Python, the general response is 
> "why did they came up with that hare brained idea!?". I cannot find 
> another answer then to say that the python developers in this case 
> created the infrastructure but forgot the syntax. Whether or not that is 
> the case, I think you can fairly argue that the present syntax goes 
> against the grain of one of Python's core qualities: code clarity.
> 
> Any thoughts or remarks?
> 
> (Or am I missing something here? In the PEP 318 Guido van Rossum is 
> stated to express "skepticism about the concept")

I think the concept of decorators is great, but I don't like the syntax:
def foo(cls) using [synchronized(lock), classmethod]:
     pass

What would be a really nice syntax that has the disadvantage of being 
totally insane, but seems much more logical / expressive to me:

classmethod foo(cls):
   pass

synchronized(lock) classmethod foo(cls):
   pass

Or in a more standard way:

def classmethod foo(cls):
   pass

def synchronized(lock) classmethod foo(cls):
   pass

Anyway the syntactic concept here is using the decorator as an 
adjective: define *this* kind of method. I think this represents the 
intent of the statement better than using [list of functions] does.

Well there's been lots of discussion about this before and I'm not 
neccessarily adding much new but you asked :-)

David



More information about the Python-list mailing list