RE: [Python-Dev] method decorators (PEP 318)
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
Greg> def [type2trans] foo(args) [type1trans, type1trans...]: Greg> ... Greg> Greg> or Greg> Greg> def foo [type2trans] (args) [type1trans, type1trans...]: Tim> Hmm - this seems like it has possibilities. Since we could only Tim> have one decorator that returned a descriptor, we could dispense Tim> with the [] on those ... Has anyone considered the side effect of any of these proposals would have on auxiliary tools like syntax-directed editors, other code colorizers, etc? Skip
On Mon, 2004-03-29 at 07:28, Skip Montanaro wrote:
Has anyone considered the side effect of any of these proposals would have on auxiliary tools like syntax-directed editors, other code colorizers, etc?
I have <wink>. Using square brackets makes things easier, and in fact current cvs for python-mode.el supports the style Guido was favoring at pycon. -Barry
Skip Montanaro <skip@pobox.com>:
Has anyone considered the side effect of any of these proposals would have on auxiliary tools like syntax-directed editors, other code colorizers, etc?
Yes, and those considerations point towards it being a bad idea to put anything either between the 'def' and the function name, or between the function name and the arg list. Doing either of those is likely to break any existing tools that think they know what a function definition looks like. Teaching those tools about the new syntax could also be quite difficult, since e.g. it may no longer be possible to express what is being looked for using a regular expression. So I think I'm against my own suggestion of putting the descriptor decorator before the arg list. But I still think it may be worth distinguishing it syntactically somehow, since it does something very different from the others, and the user will have to know that. Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
At 11:42 AM 3/30/04 +1200, Greg Ewing wrote:
So I think I'm against my own suggestion of putting the descriptor decorator before the arg list. But I still think it may be worth distinguishing it syntactically somehow, since it does something very different from the others, and the user will have to know that.
They'll know -- it always has to be the *last* decorator, or the code won't work properly. :)
"Phillip J. Eby" <pje@telecommunity.com>:
They'll know -- it always has to be the *last* decorator, or the code won't work properly. :)
If Guido is right in thinking that classmethod and staticmethod deserve to be given high prominence, they ought to be the *first* decorator. So maybe evaluation should go in the other direction? Greg Ewing, Computer Science Dept, +--------------------------------------+ University of Canterbury, | A citizen of NewZealandCorp, a | Christchurch, New Zealand | wholly-owned subsidiary of USA Inc. | greg@cosc.canterbury.ac.nz +--------------------------------------+
participants (5)
-
Barry Warsaw -
Delaney, Timothy C (Timothy) -
Greg Ewing -
Phillip J. Eby -
Skip Montanaro