IPython, @, and option E from the wiki
![](https://secure.gravatar.com/avatar/da7086d89a7978ed658143c1d4c66c77.jpg?s=120&d=mm&r=g)
Hi all, since the developers have been kind enough to take ipython's fate into account in the decorator debate, I figured I'd post an additional piece of info. Option E on the Wiki http://www.python.org/moin/PythonDecorators is: E. pie decorator at top of function body syntax def foo(arg1,arg2): @classmethod ... def bar(low,high): @accepts(int,int) @returns(float) ... I just want to mention a couple of things regarding this one, in case it becomes a contender in Guido's mind: 1. It would NOT cause ipython any problems whatsoever. Ipython only special-cases @foo at the beginning of a line, so this would be perfectly OK with ipython. I don't know if Leo would fare equally well with it. 2. I happen to like it quite a bit, since I already consider (because of the special role of docstrings) the top area of a function 'special'. So that area seems to me a reasonable choice for additional meta-information about the function's behavior. I agree decorators are more radical than docstrings, but at least there's a certain conceptual precedent. And it seems to leave the cleanness of the 'def' word which is a nice visible highlight of a function declaration, without causing the deep indentation issues of other proposals. 3. In this kind of setup, using | instead of @ would be ok as well, I guess: def bar(low,high): |accepts(int,int) |returns(float) ... Ok, nobody really wanted my opinion, so feel free to ignore #2/3 :) The main point was #1. Best, f
![](https://secure.gravatar.com/avatar/e0ec20df0fae456afa4cfeb81725e42d.jpg?s=120&d=mm&r=g)
3. In this kind of setup, using | instead of @ would be ok as well, I guess: Fernando Perez <fperez528@yahoo.com>:
def bar(low,high): |accepts(int,int) |returns(float)
How about def bar(low,high): ...accepts(int,int) ...returns(float) 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 +--------------------------------------+
![](https://secure.gravatar.com/avatar/da7086d89a7978ed658143c1d4c66c77.jpg?s=120&d=mm&r=g)
Greg Ewing wrote:
3. In this kind of setup, using | instead of @ would be ok as well, I guess: Fernando Perez <fperez528@yahoo.com>:
def bar(low,high): |accepts(int,int) |returns(float)
How about
def bar(low,high): ...accepts(int,int) ...returns(float)
The ellipsis is alredy valid python syntax elsewhere: In [7]: a=arange(3**3) In [8]: a.shape=(3,3,3) In [9]: a[:,...,:] Out[9]: array([[[ 0, 1, 2], [ 3, 4, 5], [ 6, 7, 8]], [[ 9, 10, 11], [12, 13, 14], [15, 16, 17]], [[18, 19, 20], [21, 22, 23], [24, 25, 26]]]) I don't think it would be a good idea to make it do this kind of double-duty. best, f
participants (2)
-
Fernando Perez
-
Greg Ewing