[Python-Dev] method decorators (PEP 318)
Delaney, Timothy C (Timothy)
tdelaney at avaya.com
Sun Mar 28 22:33:53 EST 2004
> From: Greg Ewing
>
> Particularly considering the latter restriction, I'm wondering whether
> these should be treated differently in the syntax. Maybe something
> like
>
> def [type2trans] foo(args) [type1trans, type1trans...]:
> ...
>
> or
>
> def foo [type2trans] (args) [type1trans, type1trans...]:
> ...
>
> This might also help satisfy Guido's concerns about the positioning
> of 'classmethod' and 'staticmethod', since, being type 2 transformers,
> they would go up front.
Hmm - this seems like it has possibilities. Since we could only have one decorator that returned a descriptor, we could dispense with the [] on those, leading to:
def descriptor_trans func_name (func_args) [callable_trans, callable_trans, ...]:
...
e.g.
def classmethod foo (cls, arg1, arg2) [synchronized(lock)]:
pass
which I think satisfies most the (IMO) most important requirements that various people have put forwards, namely:
1. `classmethod` and `staticmethod` are very important and should be very obvious (Guido seems absolutely adamant on this);
2. The name of the method should be near `def`;
3. There should be nothing between the name of the function and the arguments.
Tim Delaney
More information about the Python-Dev
mailing list