[Python-Dev] Re: PEP 318: Decorators last before colon

Delaney, Timothy C (Timothy) tdelaney at avaya.com
Wed Mar 31 17:55:51 EST 2004


python-dev-bounces+tdelaney=avaya.com at python.org wrote:

> If you spell decorators this way:
> 
> 	[decorator]
> 	def func():
> 		pass
> 
> then what will happen when you type [decorator] at an interactive
> interpreter prompt?
> 
> 	>>> [decorator]

I've been waiting and reading all the threads before chiming in ...

At first the 

    [decorator]
    def func():
        pass

had some appeal, although I definitely didn't like it as much as:

    def func() [decorator]:
        pass

because it split the function definition up into two bits - I lose the association with the def.

However, as these threads have progressed, it's become obvious to me that there are too many ways in which this is a special case for me to be happy with it. I've seen lots of objections brought up based on existing behaviours with the construct, and each time it's been waved away as not being common enough to worry about. These are often actual use cases that experienced developers have - documentation tools, editor configuration, etc.

Well, it is worrying me. Each special case is one more thing that adds a burden to using Python. The fact that whitespace and comments are allowed between the decorator and function definition is particularly worrying to me - it can quite easily mask errors in code - particularly newbie errors:

    [a]  # oops - I copied this from an interactive session and forgot to modify it.

    # This is a simple function
    def func (args):
        pass

Tim Delaney



More information about the Python-Dev mailing list