![](https://secure.gravatar.com/avatar/5a2d56afc1b00fb87dbe5e2387f0072f.jpg?s=120&d=mm&r=g)
The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so. We're aiming for 2.4a2 this Thursday - so can people please hold off on checking into the trunk from Wednesday evening onwards, please. At the moment, I'm guessing we're going to have a 2.4a3 in a couple of weeks. Anthony -- Anthony Baxter <anthony@interlink.com.au> It's never too late to have a happy childhood.
![](https://secure.gravatar.com/avatar/dbdddb64dc47a7853e836edfed6b1f3f.jpg?s=120&d=mm&r=g)
Anthony Baxter wrote:
The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so.
We're aiming for 2.4a2 this Thursday - so can people please hold off on checking into the trunk from Wednesday evening onwards, please.
At the moment, I'm guessing we're going to have a 2.4a3 in a couple of weeks.
@staticmethod ... def x(): ... pass ...
I'm getting the following assertion from a debug build: Python 2.4a1+ (#1, Aug 2 2004, 11:21:35) [GCC 2.96 20000731 (Red Hat Linux 7.3 2.96-113)] on linux2 Type "help", "copyright", "credits" or "license" for more information. python: Python/ceval.c:868: PyEval_EvalFrame: Assertion `(stack_pointer - f->f_valuestack) <= f->f_stacksize' failed. Aborted Bye, Walter Dörwald
![](https://secure.gravatar.com/avatar/0b220fa4c0b59e883f360979ee745d63.jpg?s=120&d=mm&r=g)
On Mon, 2 Aug 2004, Anthony Baxter wrote: [...]
We're aiming for 2.4a2 this Thursday - so can people please hold off on checking into the trunk from Wednesday evening onwards, please. [...]
Would somebody mind checking this in: http://www.python.org/sf/997626 It fixes a bug in httplib which badly breaks urllib2 now that urllib2 is using httplib.HTTPConnection instead of httplib.HTTP (POSTs don't work). It includes patch and a new test, and does not require doc updates, but nobody has reviewed it yet. John
![](https://secure.gravatar.com/avatar/ae37271b0d7a816e20c4b78d819c1d44.jpg?s=120&d=mm&r=g)
I'll take a look, probably tomorrow morning. Jeremy On Mon, 2 Aug 2004 14:30:39 +0100 (GMT Daylight Time), John J Lee <jjl@pobox.com> wrote:
On Mon, 2 Aug 2004, Anthony Baxter wrote: [...]
We're aiming for 2.4a2 this Thursday - so can people please hold off on checking into the trunk from Wednesday evening onwards, please. [...]
Would somebody mind checking this in:
http://www.python.org/sf/997626
It fixes a bug in httplib which badly breaks urllib2 now that urllib2 is using httplib.HTTPConnection instead of httplib.HTTP (POSTs don't work).
It includes patch and a new test, and does not require doc updates, but nobody has reviewed it yet.
![](https://secure.gravatar.com/avatar/0b220fa4c0b59e883f360979ee745d63.jpg?s=120&d=mm&r=g)
On Mon, 2 Aug 2004, Jeremy Hylton wrote:
On Mon, 2 Aug 2004 14:30:39 +0100 (GMT Daylight Time), John J Lee <jjl@pobox.com> wrote: [...]
Would somebody mind checking this in:
http://www.python.org/sf/997626
It fixes a bug in httplib which badly breaks urllib2 now that urllib2 is using httplib.HTTPConnection instead of httplib.HTTP (POSTs don't work).
It includes patch and a new test, and does not require doc updates, but nobody has reviewed it yet.
I'll take a look, probably tomorrow morning.
Jeremy [...]
It don't think it's in especial need of reviewing by an expert. It just needs to get checked in! John
![](https://secure.gravatar.com/avatar/01aa7d6d4db83982a2f6dd363d0ee0f3.jpg?s=120&d=mm&r=g)
On Mon, 2004-08-02 at 10:40, Phillip J. Eby wrote:
At 04:32 PM 8/2/04 +1000, Anthony Baxter wrote:
The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so.
@decorator won? When did that happen?
First I heard about it was when I saw Anthony's checkin messages. Maybe it was throwing that pie that inspired Guido -- an '@' does kind of look like a pie. I think Anthony's checkin message was accurate enough though -- it's the syntax everyone can hate equally. But I'm glad /something/ made it in! print>>-set-the-precedent-ly y'rs, -Barry
![](https://secure.gravatar.com/avatar/5a2d56afc1b00fb87dbe5e2387f0072f.jpg?s=120&d=mm&r=g)
Barry Warsaw wrote:
On Mon, 2004-08-02 at 10:40, Phillip J. Eby wrote:
@decorator won? When did that happen?
First I heard about it was when I saw Anthony's checkin messages. Maybe it was throwing that pie that inspired Guido -- an '@' does kind of look like a pie. I think Anthony's checkin message was accurate enough though -- it's the syntax everyone can hate equally. But I'm glad /something/ made it in!
print>>-set-the-precedent-ly y'rs, -Barry
Hey, I was just going off Guido's decision (in email - looking back, it wasn't cc'd to python-dev, which probably explains the lack of 400 followups <wink>) Channelling the BDFL, I think the idea was to put it in 2.4a2, and see how it works for people. If it turns out that it's really really really hated, we can try something else in a3. Guido can of course follow up to this (hint hint) and give his own answers. I've been playing with it for most of the last week, on and off, and I can say that I hate it less now. The @ makes it very obvious visually what's going on, which the other syntaxes didn't. But I like Barry's idea - I think it should be referred to at the 'pie decorator syntax'. Anthony -- Anthony Baxter <anthony@interlink.com.au> It's never too late to have a happy childhood.
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 01:14 AM 8/3/04 +1000, Anthony Baxter wrote:
Barry Warsaw wrote:
On Mon, 2004-08-02 at 10:40, Phillip J. Eby wrote:
@decorator won? When did that happen?
First I heard about it was when I saw Anthony's checkin messages. Maybe it was throwing that pie that inspired Guido -- an '@' does kind of look like a pie. I think Anthony's checkin message was accurate enough though -- it's the syntax everyone can hate equally. But I'm glad /something/ made it in! print>>-set-the-precedent-ly y'rs, -Barry
Hey, I was just going off Guido's decision (in email - looking back, it wasn't cc'd to python-dev, which probably explains the lack of 400 followups <wink>)
Channelling the BDFL, I think the idea was to put it in 2.4a2, and see how it works for people. If it turns out that it's really really really hated, we can try something else in a3. Guido can of course follow up to this (hint hint) and give his own answers.
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it. That is, if someone wants to implement a decorator that's forwards and backwards-compatible, that's possible with the list syntax, but not the @ syntax.
![](https://secure.gravatar.com/avatar/b932b1e5a3e8299878e579f51f49b84a.jpg?s=120&d=mm&r=g)
On Aug 2, 2004, at 12:55 PM, Phillip J. Eby wrote:
At 01:14 AM 8/3/04 +1000, Anthony Baxter wrote:
Barry Warsaw wrote:
On Mon, 2004-08-02 at 10:40, Phillip J. Eby wrote:
@decorator won? When did that happen?
First I heard about it was when I saw Anthony's checkin messages. Maybe it was throwing that pie that inspired Guido -- an '@' does kind of look like a pie. I think Anthony's checkin message was accurate enough though -- it's the syntax everyone can hate equally. But I'm glad /something/ made it in! print>>-set-the-precedent-ly y'rs, -Barry
Hey, I was just going off Guido's decision (in email - looking back, it wasn't cc'd to python-dev, which probably explains the lack of 400 followups <wink>)
Channelling the BDFL, I think the idea was to put it in 2.4a2, and see how it works for people. If it turns out that it's really really really hated, we can try something else in a3. Guido can of course follow up to this (hint hint) and give his own answers.
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it. That is, if someone wants to implement a decorator that's forwards and backwards-compatible, that's possible with the list syntax, but not the @ syntax.
... but that also means you can still make the [decorators] syntax work in 2.4, if you want compatibility or don't like @syntax. -bob
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 01:14 PM 8/2/04 -0400, Bob Ippolito wrote:
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it. That is, if someone wants to implement a decorator that's forwards and backwards-compatible, that's possible with the list syntax, but not the @ syntax.
.. but that also means you can still make the [decorators] syntax work in 2.4, if you want compatibility or don't like @syntax.
But then why not just make that the default syntax, so that no migration is necessary, and only one syntax has to be learned/explained to people?
![](https://secure.gravatar.com/avatar/bc2071afd499daef001e75e14d7f9cce.jpg?s=120&d=mm&r=g)
Is anyone else seeing a stack overflow assertion error in test_pyclbr.py (WinMe, MSVC++6.0)? Raymond
![](https://secure.gravatar.com/avatar/7c721b6de34c82ce39324dae5214dbf8.jpg?s=120&d=mm&r=g)
[Raymond Hettinger]
Is anyone else seeing a stack overflow assertion error in test_pyclbr.py (WinMe, MSVC++6.0)?
BTW, which version of Python are you talking about? Current CVS can't compile under MSVC 6.0 anymore, because PC/pyconfig.h #defines HAVE_UINTPTR_T and HAVE_INTPTR_T now, which aren't correct for VC6, and then pyport.h goes nuts -- virtually nothing compiles anymore unless you use VC7.1.
![](https://secure.gravatar.com/avatar/bc2071afd499daef001e75e14d7f9cce.jpg?s=120&d=mm&r=g)
[Raymond Hettinger]
Is anyone else seeing a stack overflow assertion error in test_pyclbr.py (WinMe, MSVC++6.0)?
BTW, which version of Python are you talking about? Current CVS can't compile under MSVC 6.0 anymore, because PC/pyconfig.h #defines HAVE_UINTPTR_T and HAVE_INTPTR_T now, which aren't correct for VC6, and then pyport.h goes nuts -- virtually nothing compiles anymore unless you use VC7.1.
I'm still with 6.0. Had to hack a couple lines of pyport.h and socketmodule.c which worked fine until yesterday. Too bad about 6.0. I had thought the plan was to support both 6.0 and 7.1. I'm not sure what we gained by dropping 6.0 right at the end :-( Raymond
![](https://secure.gravatar.com/avatar/7c721b6de34c82ce39324dae5214dbf8.jpg?s=120&d=mm&r=g)
[Raymond Hettinger]
Too bad about 6.0. I had thought the plan was to support both 6.0 and 7.1. I'm not sure what we gained by dropping 6.0 right at the end :-(
There's no plan to support MSVC 6.0. Martin routinely checks things in that break it, and that's fine. The only reason it *has* worked until recently is that people sometimes volunteer to patch up the 6.0 part of the tree. I gave some days to that at the start, because I didn't have a machine at the time that *could* run 7.1. Now I do, so I pay a lot less attention to 6.0 (and Win98SE) now. IOW, 6.0 never had, and still doesn't have, a champion (== someone willing to keep it working) for 2.4. I would have volunteered, but your report of a stack overflow in test_pyclbr scared me away <wink>.
![](https://secure.gravatar.com/avatar/3acb8bae5a2b5a28f6fe522a4ea9b873.jpg?s=120&d=mm&r=g)
Raymond Hettinger wrote:
I'm still with 6.0. Had to hack a couple lines of pyport.h and socketmodule.c which worked fine until yesterday.
Too bad about 6.0. I had thought the plan was to support both 6.0 and 7.1. I'm not sure what we gained by dropping 6.0 right at the end :-(
Someone please read the comment in PC/pyconfig.h: /* Atleast VC 7.1 has them. If some compiler does not provide them, #ifdef appropriately .*/ #define HAVE_UINTPTR_T 1 #define HAVE_INTPTR_T 1 I did not bother checking whether VC6 has uintptr_t - that does not mean that somebody else couldn't. Hacking a couple of lines is probably the wrong approach. Properly maintaining the VC6 port (i.e. sharing the well-designed changes to a couple of lines) would be a good idea. Regards, Martin
![](https://secure.gravatar.com/avatar/3acb8bae5a2b5a28f6fe522a4ea9b873.jpg?s=120&d=mm&r=g)
Phillip J. Eby wrote:
But then why not just make that the default syntax, so that no migration is necessary, and only one syntax has to be learned/explained to people?
For a very simple reason: The time for discussion is now over. There is little point in going over all the same arguments again and again. For this alpha release, no amount of arguing will change what has been committed. You really have to organize a public outcry if you want the syntax changed before 2.4. Regards, Martin
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it.
Can it? I must've missed that. It sure sounds like an incredible hack -- how to you prevent the default behavior that the list of decorators is thrown away by the interpreter?
That is, if someone wants to implement a decorator that's forwards and backwards-compatible, that's possible with the list syntax, but not the @ syntax.
.. but that also means you can still make the [decorators] syntax work in 2.4, if you want compatibility or don't like @syntax.
But then why not just make that the default syntax, so that no migration is necessary, and only one syntax has to be learned/explained to people?
Because that syntax received significant boohs when I presented it at EuroPython. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 12:09 PM 8/2/04 -0700, Guido van Rossum wrote:
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it.
Can it? I must've missed that. It sure sounds like an incredible hack -- how to you prevent the default behavior that the list of decorators is thrown away by the interpreter?
By using sys.settrace (and a careful tracer implementation to avoid interfering with debuggers or other active tracers): def as(*decorators): if len(decorators)>1: decorators = list(decorators) decorators.reverse() def callback(frame,k,v): for d in decorators: v = d(v) frame.f_locals[k] = v add_assignment_advisor(callback) def add_assignment_advisor(callback,depth=2): """Invoke 'callback(frame,name,value)' on the next assignment in 'frame' The frame monitored is determined by the 'depth' argument, which gets passed to 'sys._getframe()'. Note that when 'callback' is invoked, the frame state will be as though the assignment hasn't happened yet, so any previous value of the assigned variable will be available in the frame's locals. (Unless there's no previous value, in which case there will be no such variable in the frame locals.) """ frame = sys._getframe(depth) oldtrace = [frame.f_trace] old_locals = frame.f_locals.copy() def tracer(frm,event,arg): if event=='call': # We don't want to trace into any calls if oldtrace[0]: # ...but give the previous tracer a chance to, if it wants return oldtrace[0](frm,event,arg) else: return None try: if frm is frame and event !='exception': # Aha, time to check for an assignment... for k,v in frm.f_locals.items(): if k not in old_locals: del frm.f_locals[k] break elif old_locals[k] is not v: frm.f_locals[k] = old_locals[k] break else: # No luck, keep tracing return tracer # Got it, fire the callback, then get the heck outta here... callback(frm,k,v) finally: # Give the previous tracer a chance to run before we return if oldtrace[0]: # And allow it to replace our idea of the "previous" tracer oldtrace[0] = oldtrace[0](frm,event,arg) # Unlink ourselves from the trace chain. frm.f_trace = oldtrace[0] sys.settrace(oldtrace[0]) return oldtrace[0] # Install the trace function frame.f_trace = tracer sys.settrace(tracer) class X(object): [as(classmethod)] def foo(cls): .... Of course, 'as' is a hack to let you use arbitrary callables as decorators, rather than having to use add_assignment_advisor directly.
That is, if someone wants to implement a decorator that's forwards and backwards-compatible, that's possible with the list syntax, but not the @ syntax.
.. but that also means you can still make the [decorators] syntax work in 2.4, if you want compatibility or don't like @syntax.
But then why not just make that the default syntax, so that no migration is necessary, and only one syntax has to be learned/explained to people?
Because that syntax received significant boohs when I presented it at EuroPython.
And "@" *didn't*??? Ah well. C'est la vie.
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Phillip J. Eby wrote:
At 12:09 PM 8/2/04 -0700, Guido van Rossum wrote:
...
Because that syntax received significant boohs when I presented it at EuroPython.
And "@" *didn't*??? Ah well. C'est la vie.
I don't remember it being presented. Maybe I missed it, or forgot. Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/107dbd4c05818a538bce7193e5647c7a.jpg?s=120&d=mm&r=g)
>> Can it? I must've missed that. It sure sounds like an incredible >> hack -- how to you prevent the default behavior that the list of >> decorators is thrown away by the interpreter? Phillip> By using sys.settrace (and a careful tracer implementation to Phillip> avoid interfering with debuggers or other active tracers): I suspect Guido might class that as an "incredible hack". ;-) Skip
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Can it? I must've missed that. It sure sounds like an incredible hack -- how to you prevent the default behavior that the list of decorators is thrown away by the interpreter?
By using sys.settrace (and a careful tracer implementation to avoid interfering with debuggers or other active tracers):
Ah, yuck. Not an acceptable solution. And it doesn't let you write [classmethod] -- you have to wrap the 'classmethod' in something relatively ugly. But let's move on.
Because that syntax received significant boohs when I presented it at EuroPython.
And "@" *didn't*??? Ah well. C'est la vie.
Indeed it didn't. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
Guido van Rossum wrote:
Can it? I must've missed that. It sure sounds like an incredible hack -- how to you prevent the default behavior that the list of decorators is thrown away by the interpreter?
By using sys.settrace (and a careful tracer implementation to avoid interfering with debuggers or other active tracers):
Ah, yuck. Not an acceptable solution. And it doesn't let you write
[classmethod]
-- you have to wrap the 'classmethod' in something relatively ugly.
Here's a brief test for a syntax-change-less implementation of this feature, not as complete as test_decorators, but a good start, I believe: def test(): try: from test import test_decorators except ImportError: test_decorators = None class DecoratorTest(object): __metaclass__ = DecoratableType def foo(self): print 'undecorated foo' decorate(staticmethod) def bar(x): print x decorate(classmethod) def baz(cls, y): print cls, y if test_decorators: counts = {} decorate(test_decorators.countcalls(counts), test_decorators.memoize) def quux(self): print 'quux called' o = DecoratorTest() o.foo() o.bar('static method on instance object') o.baz('class method on the instance') DecoratorTest.bar('static method on the class') DecoratorTest.baz('class method on the class') if test_decorators: print 'Calling quux once' o.quux() print 'Calling quux twice' o.quux() print 'Called quux', DecoratorTest.counts['quux'], 'times' And here's the implementation, without using settrace, and without requiring wrappers for individual decorators: import inspect MAGIC_NAME = '__internal_decorators_list__' class Decorator(object): def __init__(self, firstCallable, *callables): cf = inspect.currentframe() self.callables = [firstCallable] + list(callables) self.decoratesLine = cf.f_back.f_lineno + 1 cf.f_back.f_locals.setdefault(MAGIC_NAME, []).append(self) def __call__(self, f): i = iter(self.callables) f = i.next()(f) for c in i: f = c(f) return f decorate = Decorator class DecoratableType(type): def __new__(cls, name, bases, attrs): decorators = attrs.get(MAGIC_NAME, []) if decorators: del attrs[MAGIC_NAME] lines = {} for (k, v) in attrs.items(): try: source, lineno = inspect.getsourcelines(v) except: pass else: lines[lineno] = k for d in decorators: if d.decoratesLine in lines: k = lines[d.decoratesLine] attrs[k] = d(attrs[k]) return super(DecoratableType, cls).__new__( cls, name, bases, attrs) There are clear drawbacks to this approach. Metaclass required, no obvious ways to support free functions, and it depends _slightly_ hackishly on the inspect module. I think at least one of these problems can be solved (and line number handling can be made smarter to deal with intervening comments, whitespace, etc). What are the advantages? * It works with Python 2.2 and Python 2.3. * It requires no interpreter changes. It can be distributed with the standard library, as a cookbook recipe, or in the official documentation as a hint regarding more "advanced" decorator usage. * It introduces no new syntax and uses up no operator character. * It supports arbitrary expressions. * It's pure python. I realize there is little or no chance of '@decorator' being pulled from 2.4a2. I hope that something along the lines of the above will be considered, instead, for the next alpha, unless there is widespread community support for '@decorator', as opposed to the ridiculously faint support ("it's better than nothing") currently behind it. Jean-Paul Calderone
![](https://secure.gravatar.com/avatar/da7086d89a7978ed658143c1d4c66c77.jpg?s=120&d=mm&r=g)
Jp Calderone wrote:
Here's a brief test for a syntax-change-less implementation of this feature, not as complete as test_decorators, but a good start, I believe:
[...]
from 2.4a2. I hope that something along the lines of the above will be considered, instead, for the next alpha, unless there is widespread community support for '@decorator', as opposed to the ridiculously faint support ("it's better than nothing") currently behind it.
FWIW, I'd be very much +1 on something like this, which feels much more 'pythonic' and elegant to me than the @ syntax. I know I'm biased because the @ syntax will force me to change ipython and it will break current ipython for anyone wanting to use 2.4, but I'm honestly trying to assess it beyond ipython. And I still don't like it, while JP's solution seems nice and clean to me. Cheers, f
![](https://secure.gravatar.com/avatar/1635e7f7ace2221d4624b7beea817fa1.jpg?s=120&d=mm&r=g)
On Tue, 2004-08-03 at 06:36, Jp Calderone wrote:
I realize there is little or no chance of '@decorator' being pulled from 2.4a2. I hope that something along the lines of the above will be considered, instead, for the next alpha, unless there is widespread community support for '@decorator', as opposed to the ridiculously faint support ("it's better than nothing") currently behind it.
Personally I think it's not just better than nothing, it's better than any of the alternatives I've seen, including the do-nothing option. I added a comment to your blog post in defence of @decorator -- http://www.livejournal.com/users/jcalderone/3913.html?thread=2121#t2121 but lets not restart a syntax debate here. My guess is that the syntax will grow on people as they use it. If not there is the alternative of using one of the pure-python versions or just carrying on using the existing way of doing things. Mark
![](https://secure.gravatar.com/avatar/ae37271b0d7a816e20c4b78d819c1d44.jpg?s=120&d=mm&r=g)
On Tue, 03 Aug 2004 01:36:19 -0400, Jp Calderone <exarkun@divmod.com> wrote: [JP provides a partial implementation of a variant decorator approach]
I realize there is little or no chance of '@decorator' being pulled from 2.4a2. I hope that something along the lines of the above will be considered, instead, for the next alpha, unless there is widespread community support for '@decorator', as opposed to the ridiculously faint support ("it's better than nothing") currently behind it.
I'm not sure how to take your post. In particular, I don't see the implementation as the limiting factor in decorator design. We can probably implement any design that we want to. The question is actually about the preferred design. You seem to be suggesting a design where decorate() is used as a pseudo-keyword; assuming, for example, that you'd want it to work for functions as well as methods. I suspect it's futile to propose alternate designs at this point. Jeremy
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 01:36 AM 8/3/04 -0400, Jp Calderone wrote:
There are clear drawbacks to this approach. Metaclass required, no obvious ways to support free functions, and it depends _slightly_ hackishly on the inspect module. I think at least one of these problems can be solved (and line number handling can be made smarter to deal with intervening comments, whitespace, etc).
But at least *two* of those drawbacks are critical, IMO: the metaclass requirement and the absence of free function support.
What are the advantages?
* It works with Python 2.2 and Python 2.3.
* It requires no interpreter changes. It can be distributed with the standard library, as a cookbook recipe, or in the official documentation as a hint regarding more "advanced" decorator usage.
* It introduces no new syntax and uses up no operator character.
* It supports arbitrary expressions.
* It's pure python.
If those are the only advantages, one might as well use the settrace-based hack, which doesn't have the problems that this one does. Note, by the way, that your 'decorate' function can be implemented by renaming my 'as' function to 'decorate' and dropping the 'decorators.reverse()' line. (i.e. 'as(x,y,z)' is the same as 'decorate(z,y,x)'). Although my examples wrapped such calls in brackets, there's no actual need for them. (Note also that the settrace hack works for class decorations as well as functions.) (FYI: 'as' and 'add_assignment_advisor' are available in the PyProtocols CVS head, in the 'protocols.advice' module.)
I realize there is little or no chance of '@decorator' being pulled from 2.4a2. I hope that something along the lines of the above will be considered, instead, for the next alpha, unless there is widespread community support for '@decorator', as opposed to the ridiculously faint support ("it's better than nothing") currently behind it.
Actually, I'm not sure I agree that it's better than nothing. For one thing, I don't think that there's any ambiguity of interpretation when decorators are written as function calls, be it 'as(classmethod)' or 'decorate(spam)' -- and I doubt that the point was argued at EuroPython, given that Guido missed the thread about it. But... this is moot, since it clearly has been pronounced upon. That pretty much means folks who want decorators right away are left with using the hacks, and not having a syntax-compatible upgrade path. However, that's *still* better than where they were before, because none of the original syntax proposals were expected to be backward-compatible. In practical terms, all this means is that I'll just use the hacked syntax until I no longer need to support Python 2.3.
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
In practical terms, all this means is that I'll just use the hacked syntax until I no longer need to support Python 2.3.
I don't understand why you prefer your hack over the established way to do decorators pre-2.4, which is def foo(): ... foo = staticmethod(foo) This works across releases (including IronPython), doesn't require any magic, is documented, etc. So if your main constraint is that it be implementable pre-2.4, you already have a solution. Isn't that much better than spending effort on hacks based on sys.settrace (which are surely going to produce bafflement from users who aren't familiar with that implementation hack)? --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/01aa7d6d4db83982a2f6dd363d0ee0f3.jpg?s=120&d=mm&r=g)
On Tue, 2004-08-03 at 10:32, Guido van Rossum wrote:
I don't understand why you prefer your hack over the established way to do decorators pre-2.4, which is
def foo(): ... foo = staticmethod(foo)
This works across releases (including IronPython), doesn't require any magic, is documented, etc. So if your main constraint is that it be implementable pre-2.4, you already have a solution. Isn't that much better than spending effort on hacks based on sys.settrace (which are surely going to produce bafflement from users who aren't familiar with that implementation hack)?
+1 -Barry
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Guido van Rossum wrote:
In practical terms, all this means is that I'll just use the hacked syntax until I no longer need to support Python 2.3.
I don't understand why you prefer your hack over the established way to do decorators pre-2.4, which is
def foo(): ... foo = staticmethod(foo)
This works across releases (including IronPython), doesn't require any magic, is documented, etc. So if your main constraint is that it be implementable pre-2.4, you already have a solution. Isn't that much better than spending effort on hacks based on sys.settrace (which are surely going to produce bafflement from users who aren't familiar with that implementation hack)?
I think this is a great point. It makes me wonder if: @staticmethod def foo(): ... if sufficiently better than: def foo(): ... foo = staticmethod(foo) to justify the language change. FWIW, It isn't to me. The new syntax is yet another rule that people have to know to understand Python code they read. That's OK if it produces enough value to justify the burden. I question whether that's the case here. Perhsps the difficulty in pickling an acceptable syntax should be taken as a warning sign that there's a problem with the feature. I wonder if perhaps the feature is too powerful. In particular, the need to support passing arguments to the descriptors seemes to add a lot of syntactic burden. I think that the most compeling common applications of decorators don't need to have decorator expressions. For example, for the common cases that this is trying to solve, I'd be happy to be able to say: def staticmethod foo(): .... and allow only names as decorators. Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
I think this is a great point. It makes me wonder if:
@staticmethod def foo(): ...
if sufficiently better than:
def foo(): ... foo = staticmethod(foo)
to justify the language change. FWIW, It isn't to me.
Sigh. This discussion is going around in pointless circles; we're *months* past that point. You're wasting your time (and mine). --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Guido van Rossum wrote:
I think this is a great point. It makes me wonder if:
@staticmethod def foo(): ...
if sufficiently better than:
def foo(): ... foo = staticmethod(foo)
to justify the language change. FWIW, It isn't to me.
Sigh. This discussion is going around in pointless circles; we're *months* past that point. You're wasting your time (and mine).
Sorry. I think you'd be wise to consider the months without consensus as evidence of a problem. Don't bother wasting time with a reply. ;) Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/ae37271b0d7a816e20c4b78d819c1d44.jpg?s=120&d=mm&r=g)
On Tue, 03 Aug 2004 08:24:46 -0700, Guido van Rossum <guido@python.org> wrote:
Sigh. This discussion is going around in pointless circles; we're *months* past that point. You're wasting your time (and mine).
Is there a PEP that summarizes the current state of the decorators design? One of the goals of PEPs was to prevent design discussions from going in circles. Another goal was to keep core developers abreast of changes without having to read every message on python-dev. As you mentioned in an earlier email, I think the work on 2.4 would have been smoother if we had used the PEP process more effectively. We never had a decent PEP for the decorator syntax discussion. PEP 318 describes a particular design choice, but it's weak on rationale. There's no PEP that summarizes the various syntax options and the reason for the eventual choice. Facundo's PEP for decimal arithmetic (PEP 327) looks like an example of the right thing. I haven't followed the work closely, but it looks like the PEP describes the current state of the design and the rationale for it. The generator PEP is in better shape than it used to be. Jeremy
![](https://secure.gravatar.com/avatar/18dce07971a548e52109b8764a0f846a.jpg?s=120&d=mm&r=g)
Jim Fulton <jim@zope.com> writes:
to justify the language change. FWIW, It isn't to me. The new syntax is yet another rule that people have to know to understand Python code they read. That's OK if it produces enough value to justify the burden. I question whether that's the case here.
Perhsps the difficulty in pickling an acceptable syntax should be taken as a warning sign that there's a problem with the feature.
I just want to be clear that I know implementing my proposal involves an ugly hack, and I'm not fond of it. Nonetheless, I think it's important. I made the proposal in response to exactly the same instinct that Jim is reflecting here. If people really need a prefix syntax for decorators it would be best to at least _start_ with an implementation that doesn't involve core language changes, because the whole area looks quite perilous from a language design point of view. I'm saying without any desire to change Guido's mind about '@', but just to explain the reasons that I brought up the idea in the first place. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
I made the proposal in response to exactly the same instinct that Jim is reflecting here. If people really need a prefix syntax for decorators it would be best to at least _start_ with an implementation that doesn't involve core language changes, because the whole area looks quite perilous from a language design point of view.
We *had* an implementation without core language changes, but it was a postfix syntax. A prefix syntax should be designed with future usability in mind exclusively, unconstrained by "implementability without language changes". That's a much more stifling requirement than the requirement that existing code shouldn't be broken (which is stifling enough in itself but IMO unavoidable). --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/7c721b6de34c82ce39324dae5214dbf8.jpg?s=120&d=mm&r=g)
I want to jump into this debate, but have stayed out of it so far and just don't have time for it. But I can't let this one pass! [Jim Fulton]
... Perhsps the difficulty in pickling an acceptable syntax should be taken as a warning sign that there's a problem with the feature.
There is, in fact, no such difficulty with any of these syntaxes: I've tried pickling all of them, under both pickle.py and cPickle, and they both pickle and unpickle fine. I think this has to do with that they're really all just strings <wink>.
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 07:32 AM 8/3/04 -0700, Guido van Rossum wrote:
In practical terms, all this means is that I'll just use the hacked syntax until I no longer need to support Python 2.3.
I don't understand why you prefer your hack over the established way to do decorators pre-2.4, which is
def foo(): ... foo = staticmethod(foo)
For the same reason that PEP 318 was written in the first place: to improve readability.
This works across releases (including IronPython), doesn't require any magic, is documented, etc.
True; and most of my existing decorator-using code works this way, and I don't plan on rushing out to change any of it any time soon.
Isn't that much better than spending effort on hacks based on sys.settrace (which are surely going to produce bafflement from users who aren't familiar with that implementation hack)?
Well, up until recently, I thought the [] syntax was still a shoo-in and that the settrace hack was just going to be a way to write backwards-compatible code. In the meantime, I've implemented a predicate-dispatch generic function system using the settrace hack for PyProtocols 1.0, and don't want to have to put off using it until 2.4. (FWIW, I still support 2.2.2, so "until 2.4" means maybe 1-2 years for me.) It looks like this: [when("isinstance(x,Foo) and y>23")] def do_something(x,y): # code for when x is a Foo and y>23 [when("isinstance(x,Bar) and y<99")] def do_something(x,y): # code for when x is a Bar and y<99 Rendered without any decorator syntax, it would have to be something like: def do_something_x_Foo_y_gt_23(x,y): # code for when x is a Foo and y>23 do_something.add("isinstance(x,Foo) and y>23", do_something_x_Foo_y_gt_23) def do_something_x_Bar_y_lt_99(x,y): # code for when x is a Bar and y>99 do_something.add("isinstance(x,Bar) and y>23", do_something_x_Bar_y_lt_99) ...which is a significant loss in readability. Now, it's true that this will just become '@when("whatever")' in 2.4, and I'm *fine* with that, just disappointed that the syntax won't be forward compatible. Indeed, what I'd rather focus on is making sure that the *semantics* will be forward compatible. Which I think they will be. What I'll probably do is make 'when()' and other decorators return a callable that deactivates the trace hack as a side effect of performing the decoration. That way, [when()] and @when() can coexist in a code base during the migration period.
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Now, it's true that this will just become '@when("whatever")' in 2.4, and I'm *fine* with that, just disappointed that the syntax won't be forward compatible.
Implementability in 2.2 and 2.3 was never on the list of requirements for decorators. You're adding this constraint yourself. I know it was brought up before but I never agreed with that constraint (and the previous community favorite, [...]-after-args, wasn't compatible either). I presume your framework is already full of hacks, which is fine by me, but I don't want to use it as a deciding factor for the decorator syntax. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 08:23 AM 8/3/04 -0700, Guido van Rossum wrote:
Now, it's true that this will just become '@when("whatever")' in 2.4, and I'm *fine* with that, just disappointed that the syntax won't be forward compatible.
Implementability in 2.2 and 2.3 was never on the list of requirements for decorators. You're adding this constraint yourself. I know it was brought up before but I never agreed with that constraint (and the previous community favorite, [...]-after-args, wasn't compatible either).
All understood and agreed. I was only trying to answer the question that you asked; I was emphatically *not* trying to reopen the discussion. My "disappointment" here is on a par with being disappointed that a restaurant is out of my favorite dish: a trifling matter that doesn't deserve the time I've already spent on it, except that I hate being judged poorly for something that I didn't actually *do*. You seem to think that I'm saying "@" is a bad thing, or that "[]" is better for the language or community than "@". But I'm most emphatically *not* saying those things, and don't believe I ever have.
I presume your framework is already full of hacks,
Well, I don't know if I'd call 4 hacks "full", especially since two of those are to implement decorators (class level and function level). The other two are to implement 'call-next-method' for generic functions, and to implement microthreads with generators. Out of nearly ninety thousand of lines of Python, I don't think that "full" is an accurate characterization here.
which is fine by me, but I don't want to use it as a deciding factor for the decorator syntax.
I'm not asking you to, and I don't believe I ever have. I only replied to J.P. Calderone's suggestion of a less-functional hack (i.e. if you're going to hack, you might as well make it do the whole thing), and to *your* emails inquiring why I and other people thought a call-oriented syntax was better than bare "[]". With regard to the actual language change, I conceded the point when you said "let's move on" the other day. I understand your frustration with this issue, and I can also understand that you are probably feeling pretty second-guessed right now, but *I'm* not second-guessing you! So there's no call for the Spanish Inquisition here, and certainly not for personal insults because I answered questions that *you* asked. (The Python standard library actually has *six* modules or packages that use sys._getframe(), not including tests; shall we call it "full of hacks", too?)
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Here's a brief test for a syntax-change-less implementation of this feature, not as complete as test_decorators, but a good start, I believe:
[fast forward to syntax example]
decorate(staticmethod) def bar(x): print x
decorate(classmethod) def baz(cls, y): print cls, y
I'm speechless. If the ambiguous [classmethod] def foo(x): ... is rejected because it doesn't look like it does something to foo, how come there's suddenly a crop of solutions that have the same problem being proposed? What you write looks like a call to the function decorate(), followed by a function method definition. The "action-at-a-distance" that is presumed by the decorate() call is difficult to explain and a precedent for other worse hacks. Its only point in favor seems to be that it doesn't use '@'. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 07:04 AM 8/3/04 -0700, Guido van Rossum wrote:
Here's a brief test for a syntax-change-less implementation of this feature, not as complete as test_decorators, but a good start, I believe:
[fast forward to syntax example]
decorate(staticmethod) def bar(x): print x
decorate(classmethod) def baz(cls, y): print cls, y
I'm speechless. If the ambiguous
[classmethod] def foo(x): ...
is rejected because it doesn't look like it does something to foo, how come there's suddenly a crop of solutions that have the same problem being proposed?
Because '[foo]' is absolutely a list with no side effects in today's Python. But '[foo()]' clearly *can* have some side effect, so if you're reading the code you have to look up 'foo' to understand what's happening there. This isn't at all sudden, btw: David Abrahams made the first 'decorate' proposal in June, and suggested the idea of using the debugger hook to implement it. I thought that one of the best parts of David Abrahams' idea was that requiring a function call made the [] syntax less ambiguous.
What you write looks like a call to the function decorate(), followed by a function method definition. The "action-at-a-distance" that is presumed by the decorate() call is difficult to explain and a precedent for other worse hacks.
I agree, which is why I wrap my decorators in [], even though it has no effect on the actual operation. It's pure "eye candy" sprinkled with syntactic sugar. :)
Its only point in favor seems to be that it doesn't use '@'.
Well, the other point is that it allows you to use C# syntax. Note that if it were spelled: [classmethod()] def foo(x): ... this would also resolve the ambiguity (IMO).
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Because '[foo]' is absolutely a list with no side effects in today's Python. But '[foo()]' clearly *can* have some side effect, so if you're reading the code you have to look up 'foo' to understand what's happening there.
Too subtle for the folks who argued against [foo] on grounds of ambiguity I think.
This isn't at all sudden, btw: David Abrahams made the first 'decorate' proposal in June, and suggested the idea of using the debugger hook to implement it. I thought that one of the best parts of David Abrahams' idea was that requiring a function call made the [] syntax less ambiguous.
And I think it is one of the worst. sys.settrace is an implementation feature not a language feature.
Well, the other point is that it allows you to use C# syntax. Note that if it were spelled:
[classmethod()] def foo(x): ...
this would also resolve the ambiguity (IMO).
Not IMO, that would just add more mystery (and would require yet another hack in classmethod to allow it to be called without args). --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/1aaefffa5063a104660952aa334022b0.jpg?s=120&d=mm&r=g)
Just a question, when "as" become a keyword in Python 3, can we expect a new syntax using that keyword instead (or additionally)? There's multiple possible syntaxes using "as", even replacing simply @ by "as" would be an improvement IMHO, since that would be english-readable (as static method define foo), like most of Python. Guido van Rossum wrote:
Not IMO, that would just add more mystery (and would require yet another hack in classmethod to allow it to be called without args).
Regards, Nicolas
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Just a question, when "as" become a keyword in Python 3, can we expect a new syntax using that keyword instead (or additionally)? There's multiple possible syntaxes using "as", even replacing simply @ by "as" would be an improvement IMHO, since that would be english-readable (as static method define foo), like most of Python.
When 'as' becomes a keyword, it is open for use in other syntax, but it won't be used for decorators (as long as I'm BDFL). 'as' suggests a renaming (like it does in import and in SQL) or perhaps a type (I've seen "as duck" in a new vaguely Pythonic language named "boo"), but that's not what decorators doo. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
Guido van Rossum wrote:
[snip]
I'm speechless. If the ambiguous
[classmethod] def foo(x): ...
is rejected because it doesn't look like it does something to foo, how come there's suddenly a crop of solutions that have the same problem being proposed? What you write looks like a call to the function decorate(), followed by a function method definition. The "action-at-a-distance" that is presumed by the decorate() call is difficult to explain and a precedent for other worse hacks. Its only point in favor seems to be that it doesn't use '@'.
In my view, the strongest point in favor of a solution that involves calling functions rather than changing syntax is that the functions involved can be placed in the standard library rather than the interpreter. I believe a widely held view is that features can be supported by the stdlib do not merit language changes? Moreover, I have the impression that many people are clamoring for this feature, no matter how it ends up looking, because they simply *must have it*. Well, if they must have it, why wait for 2.4, when clearly they can have it right now? Jp
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
In my view, the strongest point in favor of a solution that involves calling functions rather than changing syntax is that the functions involved can be placed in the standard library rather than the interpreter.
I believe a widely held view is that features can be supported by the stdlib do not merit language changes?
No viewpoint ought to be held to the exclusion of all others. Using functions with "action-at-a-distance" through sys.settraceback may be okay for an obscure feature that can't be had any other way yet doesn't merit changes to the language, but that's not the situation for decorators. The widely held view here is that decorators need to be added as a syntactic feature to avoid the problems with the postfix notation used in 2.2 and 2.3. Decorators are slated to be an important new language feature and their design needs to be forward-looking, not constrained by what can be implemented in 2.3. One important feature of @deco (and of [deco] prefix as I proposed it) is that it is a compile-time feature. This has all sorts of advantages, since future compilers and tools will be able to know more about methods. Solutions based on sys.settrace fail badly here.
Moreover, I have the impression that many people are clamoring for this feature, no matter how it ends up looking, because they simply *must have it*. Well, if they must have it, why wait for 2.4, when clearly they can have it right now?
Sure, but that's not an argument against improving their situation in 2.4. If I had any hope that something better than @deco was possible but hasn't been discovered yet, I'd be holding off too. But I don't think that's the case. Every solution proposed has its own set of drawbacks, and the drawbacks aren't getting resolved by waiting. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
Guido van Rossum wrote:
No viewpoint ought to be held to the exclusion of all others. Using functions with "action-at-a-distance" through sys.settraceback may be okay for an obscure feature that can't be had any other way yet doesn't merit changes to the language, but that's not the situation for decorators. The widely held view here is that decorators need to be added as a syntactic feature to avoid the problems with the postfix notation used in 2.2 and 2.3. Decorators are slated to be an important new language feature and their design needs to be forward-looking, not constrained by what can be implemented in 2.3.
Just to be clear, the implementation I shared did not use sys.settrace(). It did rely on inspect.currentframe(), but so do a handful of other stdlib modules (as PJE pointed out).
One important feature of @deco (and of [deco] prefix as I proposed it) is that it is a compile-time feature. This has all sorts of advantages, since future compilers and tools will be able to know more about methods. Solutions based on sys.settrace fail badly here.
Moreover, I have the impression that many people are clamoring for this feature, no matter how it ends up looking, because they simply *must have it*. Well, if they must have it, why wait for 2.4, when clearly they can have it right now?
Sure, but that's not an argument against improving their situation in 2.4.
If it is truly an improvement. Here we (and many others) disagree. I like Python(*) because it is simple and generally unsurprising. I think that '@deco' adds complexity, both for beginners and experienced programmers alike, so I do not see it as an improvement. I am content with "foo = deco(foo)" and various metaclass-based automatic decorations, and see no need for them to be moved into the core. I may be free to not use the '@deco' syntax in 2.4, but that will not prevent me from having to read it in the code of others, or from explaining it to other Python programmers. None of these are new points, so I don't expect a response to them.
If I had any hope that something better than @deco was possible but hasn't been discovered yet, I'd be holding off too. But I don't think that's the case. Every solution proposed has its own set of drawbacks, and the drawbacks aren't getting resolved by waiting.
How many features that everyone hates can Python support? The Zen of Python might state that practicality beats purity, but if it continues to do so, time after time, at some point we're going to look up and wonder where that clean, readable, maintainable programming language we all loved has gone. Jp (*) And I really do like Python. A lot. Of the software I now write, at least 99.9% of it is in Python. The developers of this language _almost_ always show more good sense, intelligence, and skill than most other groups I can think of. You all deserve more praise than you're given.
![](https://secure.gravatar.com/avatar/d6b9415353e04ffa6de5a8f3aaea0553.jpg?s=120&d=mm&r=g)
"Jp Calderone" <exarkun@divmod.com> wrote in message news:410FC9FE.6060305@divmod.com...
I like Python(*) because it is simple and generally unsurprising.
Me too.
I think that '@deco' adds complexity, both for beginners and experienced programmers alike,
Decorators will add complexity, regardless of syntax. An advantage of the @ syntax is than it makes the complexiity separable and ignorable for someone learning/teaching basic Python, which includes list literals and function defs. To me, the [deco list] syntax is particularly bad in adding an advanced, esoteric, context-dependent, magic meaning to an hour 1 basic concept.
so I do not see it as an improvement.
Apparently, the question of whether decos are an improvement has at least temporarily been decided in the affirmative. Terry J. Reedy
![](https://secure.gravatar.com/avatar/c9c798a3dcd710c4c677aab26344ba68.jpg?s=120&d=mm&r=g)
On Tue, Aug 03, 2004 at 08:25:19PM -0400, Terry Reedy wrote:
Apparently, the question of whether decos are an improvement has at least temporarily been decided in the affirmative.
That's not apparent to me. It seems to me that most people just got sick of the endless debate and tuned out. The people who had urgent need for the feature were probably a bit more persistent. Personally, I don't see the cost vs. benefit of the feature to be compelling. It seems there is not a lot you can do with a decorator without resorting to ugly hacks (e.g. messing with bytecode). returning-to-tuned-out-mode-ly yr's Neil
![](https://secure.gravatar.com/avatar/135b00c97cc7af2e25f4f23b10e02d48.jpg?s=120&d=mm&r=g)
That's not apparent to me. It seems to me that most people just got sick of the endless debate and tuned out.
It's also entirely possible that "most people" were happy with the way things were going and chose not to post... My personal opinion is that the pie syntax is acceptable, and the continuing debate is doing harm and providing no enlightenment. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/
![](https://secure.gravatar.com/avatar/7c721b6de34c82ce39324dae5214dbf8.jpg?s=120&d=mm&r=g)
[Andrew McNamara]
It's also entirely possible that "most people" were happy with the way things were going and chose not to post...
I was indeed "happy enough".
My personal opinion is that the pie syntax is acceptable,
Ditto. It does simple things quite well, and it makes it obvious they're being done. Then again, I like "print >> fileobj" too <0.7 wink>.
and the continuing debate is doing harm
We're in no danger of running out of pixels.
and providing no enlightenment.
That's for sure. In the old days, Guido would Pronounce, and we'd all bite our tongues (although not necessarily each his own). The less time Guido can make for Python, the more important becomes graceful capitulation.
![](https://secure.gravatar.com/avatar/01aa7d6d4db83982a2f6dd363d0ee0f3.jpg?s=120&d=mm&r=g)
On Tue, 2004-08-03 at 21:07, Neil Schemenauer wrote:
That's not apparent to me. It seems to me that most people just got sick of the endless debate and tuned out. The people who had urgent need for the feature were probably a bit more persistent. Personally, I don't see the cost vs. benefit of the feature to be compelling. It seems there is not a lot you can do with a decorator without resorting to ugly hacks (e.g. messing with bytecode).
I disagree. I've written a lot of code that uses pre-pie decorators, but it's all fairly localized. It isn't spread out in every module, but it's contained, e.g., within a database package (wrap mutators in transaction handling decorators). Those use my own custom decorator, but in almost all other examples (in my own code -- I know others have different use cases), the decorators are built-ins like property, staticmethod, etc. For me, the benefit is significant because while I would still continue to use this particular feature, I think the pie decorator syntax makes the code /more/ readable, or more readable in the right way and in the right place. In general, I predict most Python code will continue to be blissfully unadorned with decorators. -Barry
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
In general, I predict most Python code will continue to be blissfully unadorned with decorators.
Right. Outside the test suite, there are very few uses of classmethod, staticmethod and property in the standard library. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Terry Reedy wrote: ...
Decorators will add complexity, regardless of syntax.
Especially in their current over-powered form. If decorators didn't have to take arguments, then you could use a syntax like: def classmethod foo(cls, ...): ... This does add complexity, but I think it enhances understandability. I understand why some people want to be able to pass arguments to decorators, but frankly, I find many of the examples of doing so down right scary.
An advantage of the @ syntax is than it makes the complexiity separable and ignorable for someone learning/teaching basic Python,
I don't agree that they are ignorable. People will see them in code and will *have* to understand what they mean. Given sme examples I've seen here, this will sometimes be a significant chalenge. Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/135b00c97cc7af2e25f4f23b10e02d48.jpg?s=120&d=mm&r=g)
An advantage of the @ syntax is than it makes the complexiity separable and ignorable for someone learning/teaching basic Python,
I don't agree that they are ignorable. People will see them in code and will *have* to understand what they mean. Given sme examples I've seen here, this will sometimes be a significant chalenge.
There are a number of "advanced" features in python that could be a barrier to understanding for new users, but which are rarely seen in practice - metaclasses being the classic example. I imagine these features are rarely seen because most people don't understand them, and those that do have the good taste not to use them gratuitously. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Andrew McNamara wrote:
An advantage of the @ syntax is than it makes the complexiity separable and ignorable for someone learning/teaching basic Python,
I don't agree that they are ignorable. People will see them in code and will *have* to understand what they mean. Given sme examples I've seen here, this will sometimes be a significant chalenge.
There are a number of "advanced" features in python that could be a barrier to understanding for new users, but which are rarely seen in practice - metaclasses being the classic example.
I imagine these features are rarely seen because most people don't understand them, and those that do have the good taste not to use them gratuitously.
This feature won't be rarely used. Class and static methods and properties are created fairly often, certainly far more often than meta classes. Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/135b00c97cc7af2e25f4f23b10e02d48.jpg?s=120&d=mm&r=g)
There are a number of "advanced" features in python that could be a barrier to understanding for new users, but which are rarely seen in practice - metaclasses being the classic example.
I imagine these features are rarely seen because most people don't understand them, and those that do have the good taste not to use them gratuitously.
This feature won't be rarely used. Class and static methods and properties are created fairly often, certainly far more often than meta classes.
Sorry, what I meant was advanced uses of decorators will be rare. Certainly "staticmethod" and "classmethod" will be common. It's a personal opinion, but I find @staticmethod easier to parse visually than the current situation. -- Andrew McNamara, Senior Developer, Object Craft http://www.object-craft.com.au/
![](https://secure.gravatar.com/avatar/b932b1e5a3e8299878e579f51f49b84a.jpg?s=120&d=mm&r=g)
On Aug 4, 2004, at 9:46 AM, Jim Fulton wrote:
Terry Reedy wrote:
...
Decorators will add complexity, regardless of syntax.
Especially in their current over-powered form. If decorators didn't have to take arguments, then you could use a syntax like:
def classmethod foo(cls, ...): ...
This does add complexity, but I think it enhances understandability.
I understand why some people want to be able to pass arguments to decorators, but frankly, I find many of the examples of doing so down right scary.
All of the important use cases I've found and seen for decorators have arguments. PyObjC and ctypes (possibly Jython, IronPython) will use them to specify the input and output argument types for a function (integers, pointers, etc.). PJE has cooked up some interesting stuff using decorators to do generic functions. I use these sorts of things far more often than classmethod and staticmethod (or the like). I can also imagine using them for something like decorating functions with four character suite and event codes for responding to AppleEvents in Mac apps. I wouldn't really care for decorators at all if I couldn't use them to these sorts of things. Your proposal would make decorators nearly as bad as the current pre-2.4 situation. This is REALLY ugly: foo = decorator(....) @foo def fun(....): ... -bob
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Bob Ippolito wrote:
...
Your proposal would make decorators nearly as bad as the current pre-2.4 situation. This is REALLY ugly:
foo = decorator(....) @foo def fun(....): ...
I agree, that's really ugly. I wasn't proposing that. I proposed not allowing decorator arguments. Without decorator arguments, a much simpler syntax can be used, as in: def classmethod foo(...): ... Or, alternatively, I'm proposing allowing the above simpler syntax when arguments are not needed and allowing the pie syntax to handle more complex cases. The original motivation for decirators was to deal with things like properties and specialized methods. I'd like to see these cases handled well. I think these are going to be the most common cases and the cases that new Python programmers are most likely to come accross. Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/b932b1e5a3e8299878e579f51f49b84a.jpg?s=120&d=mm&r=g)
On Aug 4, 2004, at 11:00 AM, Jim Fulton wrote:
Bob Ippolito wrote: ...
Your proposal would make decorators nearly as bad as the current pre-2.4 situation. This is REALLY ugly: foo = decorator(....) @foo def fun(....): ...
I agree, that's really ugly. I wasn't proposing that.
I proposed not allowing decorator arguments. Without decorator arguments, a much simpler syntax can be used, as in:
def classmethod foo(...): ...
Or, alternatively, I'm proposing allowing the above simpler syntax when arguments are not needed and allowing the pie syntax to handle more complex cases.
The original motivation for decirators was to deal with things like properties and specialized methods. I'd like to see these cases handled well. I think these are going to be the most common cases and the cases that new Python programmers are most likely to come accross.
Adding even more syntax sounds like a horrible idea (along with the fact that this particular syntax is hard to syntax highlight, will really confuse lots of existing tools, etc.). I also don't agree that those are the most common cases. I certainly haven't seen a whole lot of staticmethod/classmethod usage, and property is only useful for writing getters (with decorator syntax), so I don't think that will be used very often either. I think that decorators will be used about 98% for domain specific purposes with non-standard decorators and 2% will be uses of decorators that come in the standard library such as staticmethod, classmethod, and property (for writing getters). Anyway, it's probably too late to change anyone's mind. Decorators are in @as-is, and I don't think anything you can say now is going to change that. -bob
![](https://secure.gravatar.com/avatar/01aa7d6d4db83982a2f6dd363d0ee0f3.jpg?s=120&d=mm&r=g)
On Wed, 2004-08-04 at 09:46, Jim Fulton wrote:
I don't agree that they are ignorable. People will see them in code and will *have* to understand what they mean. Given sme examples I've seen here, this will sometimes be a significant chalenge.
I think most of the cognitive challenge for decorators will be in understanding the side-effects of the decorator, not in understanding the syntax for wrapping a function in a decorator. That won't change by using some other (or no new) syntax -- the Python 2.3. spelling would be just as hairy. -Barry
![](https://secure.gravatar.com/avatar/d6b9415353e04ffa6de5a8f3aaea0553.jpg?s=120&d=mm&r=g)
"Jim Fulton" <jim@zope.com> wrote in message news:4110E8CF.6070900@zope.com...
Terry Reedy wrote:
An advantage of the @ syntax is than it makes the complexiity separable and ignorable for someone learning/teaching basic Python,
I don't agree that they are ignorable.
Any advanced feature is ignorable is the context I specified -- learning/teaching basic Python.
People will see them in code and will *have* to understand what they mean.
Any ignored feature becomes unignorable when one stumbles across it in 'wild' Python and want to really understand. And even with an understanding of the general feature, specific knowledge may also be required -- of the particular module or objects imported or in this case, the particular decorator. But there is currently *lots* of publicly available code without decorators to read, and more will be written. In addition, one will be able to use at least some modules that use them without knowing about them, just as with metaclasses, for instance. My particular point was separability. With @, one will still be able to learn everything about [] and def without hearing the word decorator, and without having to revise one's understanding upon encountering decorators. This was not true of the [deco] and deco within def syntax proposals. It is a minor point, but one that is a plus for me. Terry J. Reedy
![](https://secure.gravatar.com/avatar/ae37271b0d7a816e20c4b78d819c1d44.jpg?s=120&d=mm&r=g)
On Wed, 04 Aug 2004 09:46:55 -0400, Jim Fulton <jim@zope.com> wrote:
Terry Reedy wrote:
....
Decorators will add complexity, regardless of syntax.
Especially in their current over-powered form. If decorators didn't have to take arguments, then you could use a syntax like:
def classmethod foo(cls, ...): ...
This does add complexity, but I think it enhances understandability.
I understand why some people want to be able to pass arguments to decorators, but frankly, I find many of the examples of doing so down right scary.
I wonder if we should have add a note to the Python style guide that forbids such things from the standard library <0.2 wink>.
An advantage of the @ syntax is than it makes the complexiity separable and ignorable for someone learning/teaching basic Python,
I don't agree that they are ignorable. People will see them in code and will *have* to understand what they mean. Given sme examples I've seen here, this will sometimes be a significant chalenge.
It certainly depends on the use. I don't think @classmethod will be any more or less confusing than the current practice of calling foo = staticmethod(foo) after the def. I agree that more elaborate uses may be confusing; then again, I suspect that more elaborate code will be confusing regardless of how it uses decorators. Jeremy
![](https://secure.gravatar.com/avatar/1efc90ff6075b7654d8a8ce6e51a2cd3.jpg?s=120&d=mm&r=g)
Jp Calderone <exarkun@divmod.com> writes:
How many features that everyone hates can Python support?
It's disingenuous to suggest that this or any other feature of Python is one "everyone hates". Hey, I am even quite happy with ''.join, another source of controversy that seems to have failed to completely halt the adoption of Python <wink>. Cheers, mwh -- If your telephone company installs a system in the woods with no one around to see them, do they still get it wrong? -- Robert Moir, alt.sysadmin.recovery
![](https://secure.gravatar.com/avatar/18dce07971a548e52109b8764a0f846a.jpg?s=120&d=mm&r=g)
Guido van Rossum <guido@python.org> writes:
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it.
Can it? I must've missed that. It sure sounds like an incredible hack -- how to you prevent the default behavior that the list of decorators is thrown away by the interpreter?
See http://article.gmane.org/gmane.comp.python.devel/60542 I'm really surprised you missed it, and was likewise disappointed that it wasn't included in the weekly (?) summary. It seemed like a pretty significant development to me. -- Dave Abrahams Boost Consulting http://www.boost-consulting.com
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Aug 2, 2004, at 12:55 PM, Phillip J. Eby wrote:
I would think the fact that the '[decorators]' syntax can be implemented in pure Python (no changes to the interpreter) for existing Python versions would give more weight to it. That is, if someone wants to implement a decorator that's forwards and backwards-compatible, that's possible with the list syntax, but not the @ syntax.
First off, let me just say I'm happy *one* proposal was selected for inclusion. The @foo on the line before the function was not my favorite, but that's okay. It'll definitely work. However, I do think [decorator...] on the line before the function definition would be a far worse choice than @decorator. Decorators *are* special new syntax. At least @foo *looks* like new syntax. [decorators] looks like a expression creating a list, but instead is completely magical. Magical syntax seems very poor to me. About the only advantage it has is that you can implement it via a completely horrible hack in Python < 2.4. But, that is only a temporary situation. In a few years everyone will have Python >= 2.4 and we'd still be stuck with strange weird syntax that doesn't look like syntax. The one thing I do dislike about the new addition is the arbitrary (?) restriction on expression allowed in a decorator. From Grammar.. decorator: '@' dotted_name [ '(' [arglist] ')' ] That seems quite odd to me. Is there some reason it couldn't be: decorator: '@' test ? I don't see how that would cause a problem, but maybe I've missed something. Just testing out how this syntax looks, you can ignore the rest of this mail. :) @classmethod @arguments(string, int) @returns(list) def foo(s, i): return [s]*i or perhaps the same, but with a list allowed: @classmethod, arguments(string, int), returns(list) def foo(s, i): return [s]*i or original proposal: def foo(s, i) [classmethod, arguments(string, int), returns(list)]: return [s]*i Ah well, they all have their advantages. :) This one is workable. James
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
The one thing I do dislike about the new addition is the arbitrary (?) restriction on expression allowed in a decorator. From Grammar.. decorator: '@' dotted_name [ '(' [arglist] ')' ] That seems quite odd to me. Is there some reason it couldn't be: decorator: '@' test ?
The first patch on SF actually had '@' test, and I requested that it be changed. Most things that are 'test' but not 'dotted_name' optionally followed by an argument list don't make sense as decorators; if you really have a need to write @ foo or bar def f(): ... you can write deco = foo or bar @deco def f(): ... --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/107dbd4c05818a538bce7193e5647c7a.jpg?s=120&d=mm&r=g)
I'll be happy to update PEP 318 to conform to the pie decorator syntax. Can someone describe the application order? If I have @ decorator1 @ decorator2 def func(...): ... Which decorator is applied first to the function object, decorator1 or decorator2? Thx, Skip
![](https://secure.gravatar.com/avatar/5a2d56afc1b00fb87dbe5e2387f0072f.jpg?s=120&d=mm&r=g)
Skip Montanaro wrote:
I'll be happy to update PEP 318 to conform to the pie decorator syntax. Can someone describe the application order? If I have
@ decorator1 @ decorator2 def func(...): ...
Which decorator is applied first to the function object, decorator1 or decorator2?
func = decorator1(decorator2(func)) I hope to check in a revised 318 this afternoon. Anthony
![](https://secure.gravatar.com/avatar/107dbd4c05818a538bce7193e5647c7a.jpg?s=120&d=mm&r=g)
Anthony> I hope to check in a revised 318 this afternoon. Cool. Let me know if you want any help/input/proofing/whatever... Skip
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Aug 2, 2004, at 9:05 PM, Guido van Rossum wrote:
The first patch on SF actually had '@' test, and I requested that it be changed. Most things that are 'test' but not 'dotted_name' optionally followed by an argument list don't make sense as decorators; if you really have a need to write
@ foo or bar def f(): ...
you can write
deco = foo or bar @deco def f(): ...
An even better workaround is to write: def d(arg): return arg @d(foo or bar) def f(): ... However, it seems as if this restriction creates a new class of expression for no gain. It is true enough that *most* python expressions aren't useful to write after a @, but that's also true of a lot of other places an expression can be used (e.g. before a () of a function call. A list comprehension can never result in a callable object. An arithmetic operation usually won't.). The only real necessary restriction on the @ operator is that its argument be callable and take a single argument. Many expressions could return a callable object. Why not let them? Is it really worth having a special case just to SyntaxError expressions that sometimes won't result in an appropriate callable? Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f) Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work. James
![](https://secure.gravatar.com/avatar/1e40abc43e91473ed3e5fcce74cba4bc.jpg?s=120&d=mm&r=g)
In article <110DAF75-E504-11D8-8D12-000A95A50FB2@fuhm.net>, James Y Knight <foom@fuhm.net> wrote:
@ foo or bar def f(): ...
you can write
deco = foo or bar @deco def f(): ...
An even better workaround is to write: def d(arg): return arg
@d(foo or bar) def f(): ...
However, it seems as if this restriction creates a new class of expression for no gain. It is true enough that *most* python expressions aren't useful to write after a @, but that's also true of a lot of other places an expression can be used (e.g. before a () of a function call. A list comprehension can never result in a callable object. An arithmetic operation usually won't.).
As you say, there aren't a lot of types of Python expression that return callables. The main thing this restriction seems to prevent is @lambda, and I think preventing that is a good thing. The other possibility that comes to mind is @functable[index], but I'd have to see a use case before worrying too much that it's not allowed. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/
![](https://secure.gravatar.com/avatar/7ed9784cbb1ba1ef75454034b3a8e6a1.jpg?s=120&d=mm&r=g)
James Y Knight wrote:
[snip]
An even better workaround is to write: def d(arg): return arg
@d(foo or bar) def f(): ...
However, it seems as if this restriction creates a new class of expression for no gain. It is true enough that *most* python expressions aren't useful to write after a @, but that's also true of a lot of other places an expression can be used (e.g. before a () of a function call. A list comprehension can never result in a callable object. An arithmetic operation usually won't.).
The only real necessary restriction on the @ operator is that its argument be callable and take a single argument. Many expressions could return a callable object. Why not let them? Is it really worth having a special case just to SyntaxError expressions that sometimes won't result in an appropriate callable?
Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f)
Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work.
James
For what it's worth, I agree with James completely. Jp
![](https://secure.gravatar.com/avatar/bc2071afd499daef001e75e14d7f9cce.jpg?s=120&d=mm&r=g)
The only real necessary restriction on the @ operator is that its argument be callable and take a single argument. Many expressions could return a callable object. Why not let them? Is it really worth having a special case just to SyntaxError expressions that sometimes won't result in an appropriate callable?
Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f)
Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work.
James
For what it's worth, I agree with James completely.
Jp
I concur. Raymond
![](https://secure.gravatar.com/avatar/b932b1e5a3e8299878e579f51f49b84a.jpg?s=120&d=mm&r=g)
On Aug 2, 2004, at 12:54 PM, Raymond Hettinger wrote:
The only real necessary restriction on the @ operator is that its argument be callable and take a single argument. Many expressions could return a callable object. Why not let them? Is it really worth having a special case just to SyntaxError expressions that sometimes won't result in an appropriate callable?
Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f)
Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work.
James
For what it's worth, I agree with James completely.
Jp
I concur.
Raymond
Ditto. -bob
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
James Y Knight wrote: ...
Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f)
Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work.
+1 -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/1635e7f7ace2221d4624b7beea817fa1.jpg?s=120&d=mm&r=g)
On Tue, 2004-08-03 at 05:17, James Y Knight wrote:
Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f)
Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work.
I don't think any of these seem that likely in practice, and if you do want them, it is not hard to say: # Hopefully some comment here explaining the reason why you're # doing this. And a more meaningful name than foo_or_bar! foo_or_bar = foo or bar @foo_or_bar def func(): pass I would say leave it like this for now. It is easy to relax the restriction later if there's a demand. Mark
![](https://secure.gravatar.com/avatar/1e40abc43e91473ed3e5fcce74cba4bc.jpg?s=120&d=mm&r=g)
BTW, here's another use case I haven't seen suggested yet: def substitution_for(regexp): sub = re.compile(regexp).sub return lambda func: lambda text: sub(func,text) e.g. (example from some recent code of mine, redone as a decorator) @substitution_for('[a-z][A-Z]') def camelspace(m): """Insert space into camelcase regexp match.""" return m.group(0)[0]+' '+m.group(0)[1:] ... info.title = camelspace(info.basefilename) Instead my current code defines a separate variable for the re.compile().sub object, then later has to put this variable together correctly with the undecorated camelspace function to perform the substitution. Using decorators allows the sub and replacement function to become merged into a single object with a more intuitive API. (Also, my actual code uses more than one of these substitutions...) I don't generally prefer to use explicit lambdas but expanding them out with names makes the definition of substitution_for a lot longer without much readability gain in my eyes. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
The only real necessary restriction on the @ operator is that its argument be callable and take a single argument. Many expressions could return a callable object. Why not let them? Is it really worth having a special case just to SyntaxError expressions that sometimes won't result in an appropriate callable?
Things someone might want to do, ordered roughly from most reasonable to least reasonable ;) @foo().bar() @foo or bar @mydecorators['foo'] @lambda f: foo(f) or bar(f)
Why disallow these forms? It seems quite difficult, especially, to explain why the first one does not, or should not, work.
I have a gut feeling about this one. I'm not sure where it comes from, but I have it. It may be that I want the compiler to be able to recognize certain decorators. So while it would be quite easy to change the syntax to @test in the future, I'd like to stick with the more restricted form unless a real use case is presented where allowing @test would increase readability. (@foo().bar() doesn't count because I don't expect you'll ever need that). --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Aug 3, 2004, at 10:40 AM, Guido van Rossum wrote:
I have a gut feeling about this one. I'm not sure where it comes from, but I have it.
I guess I have the opposite gut feeling: special classes of expressions in the grammar are always bad. Michael Chermside's message said this better than I can. Heck, even 'except' can take an arbitrary expression as an argument! Now I'm damn sure I'd never write code that says except FooError and f() or MyErrors[5]: because that would be insane, but I'm glad python doesn't restrict the argument to some strange subset of expressions that someone decided were approved! Consistency of grammar is a key feature, even when it allows users to write insane programs.
It may be that I want the compiler to be able to recognize certain decorators.
If I understand what you're saying, it seems that you're thinking the @ form should be more a static declaration, not a dynamically evaluated expression, so that the compiler can reason about it without running code. However, that isn't the case even now, and if it was, it wouldn't fit in with the rest of the python language very well. Definitely an interesting idea, but I think it would require the @'s argument to be a compile-time macro, instead of a run-time expression. And python doesn't have compile-time macros. With @ taking a runtime expression, I don't see how the compiler could possibly do anything with its argument. Nothing can be guaranteed. As a postscript, I must say I am alarmed by some comments others have used to justify the current restricted state. In particular (paraphrased), "it's good because it keeps people from using lambda", and "it's good because it keeps people from doing '@1+1' by mistake. For the first: you hate lambdas so much? They are in python -- arbitrarily forbidding their use in certain expressions because you don't like them is pretty strange. For the second: You want to do type checking via syntax error?! *That* is insanity. And it doesn't even work well (of course). James
![](https://secure.gravatar.com/avatar/1e40abc43e91473ed3e5fcce74cba4bc.jpg?s=120&d=mm&r=g)
In article <89EC7888-E580-11D8-8D12-000A95A50FB2@fuhm.net>, James Y Knight <foom@fuhm.net> wrote:
As a postscript, I must say I am alarmed by some comments others have used to justify the current restricted state. In particular (paraphrased), "it's good because it keeps people from using lambda", and "it's good because it keeps people from doing '@1+1' by mistake. For the first: you hate lambdas so much?
I think I was the one who posted the lambda comment. I also posted in a different message a use-case for decorators that had a line with two lambdas in it, so obviously I don't hate lambdas. I'm actually pretty neutral on restricted decorators vs @expression. But @lambda(func): body def func(...): ... is (I think) much more likely to be an abuse of language than the Pythonic way of writing something, so I don't see a lot of harm in preventing it. -- David Eppstein Computer Science Dept., Univ. of California, Irvine http://www.ics.uci.edu/~eppstein/
![](https://secure.gravatar.com/avatar/22fa72de5e9704cc47054eace0475c9b.jpg?s=120&d=mm&r=g)
David Eppstein wrote:
I'm actually pretty neutral on restricted decorators vs @expression. But @lambda(func): body def func(...): ... is (I think) much more likely to be an abuse of language than the Pythonic way of writing something, so I don't see a lot of harm in preventing it.
And, as someone pointed out, *lifting* a restriction is a heck of a lot easier than imposing one later on (even after only 1 alpha). YouAintGonnaNeedIt and all that. . . Cheers, Nick. -- Nick Coghlan | Brisbane, Australia Email: ncoghlan@email.com | Mobile: +61 409 573 268
![](https://secure.gravatar.com/avatar/15fa47f2847592672210af8a25cd1f34.jpg?s=120&d=mm&r=g)
On Aug 3, 2004, at 4:22 PM, David Eppstein wrote:
I think I was the one who posted the lambda comment. I also posted in a different message a use-case for decorators that had a line with two lambdas in it, so obviously I don't hate lambdas.
Ah, I'm sorry then. I have noticed many people seem to be quite biased against lambdas here, so I just assumed.
I'm actually pretty neutral on restricted decorators vs @expression. But @lambda(func): body def func(...): ... is (I think) much more likely to be an abuse of language than the Pythonic way of writing something, so I don't see a lot of harm in preventing it.
Oh, I agree, it's quite silly to write a piece of code like that, and if anyone wrote it in code I have to maintain I'd probably be quite irritated. So, if the conclusion to this is "well, we can always unrestrict it later, if someone comes up with a convincing use-case", then it'll likely never be changed, because I doubt that's gonna happen. The best I can do is foo().bar(), which I suspect at least one person will run into at some point and wonder about, then work around instead of presenting it to python-dev. My main argument is and has been simply: that's how everything else in python works, so this should be the same. Last message on this subject, I think everyone got the point by now and is either convinced or not. :) James
![](https://secure.gravatar.com/avatar/1efc90ff6075b7654d8a8ce6e51a2cd3.jpg?s=120&d=mm&r=g)
James Y Knight <foom@fuhm.net> writes:
Now I'm damn sure I'd never write code that says except FooError and f() or MyErrors[5]: because that would be insane,
I think class C(random.choice([dict, list])): pass is my favourite example of this :-) Cheers, mwh -- That being done, all you have to do next is call free() slightly less often than malloc(). You may want to examine the Solaris system libraries for a particularly ambitious implementation of this technique. -- Eric O'Dell, comp.lang.dylan (& x-posts)
![](https://secure.gravatar.com/avatar/e0ec20df0fae456afa4cfeb81725e42d.jpg?s=120&d=mm&r=g)
I think Anthony's checkin message was accurate enough though -- it's the syntax everyone can hate equally. But I'm glad /something/ made it in!
Well, I'm not. It seems like a decision made in haste. Maybe I'll get used to it in a few decades, but right now I feel very disappointed. We were *so* close to agreeing on something nice, and then for some reason it all went pear-shaped. :-( 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/5a2d56afc1b00fb87dbe5e2387f0072f.jpg?s=120&d=mm&r=g)
Greg Ewing wrote:
Well, I'm not. It seems like a decision made in haste.
Maybe I'll get used to it in a few decades, but right now I feel very disappointed. We were *so* close to agreeing on something nice, and then for some reason it all went pear-shaped. :-(
PEP 318 is now nearly 14 months old. There's been a truly staggering number of posts on the subject - and every time it's raised, the same points come up. The only things to have happened recently were the new @ syntax, and PJE's settrace hack. If not now, when? This could drag on for another 14 months, otherwise - and I really don't want to hold up 2.4 final for that long. Anthony -- Anthony Baxter <anthony@interlink.com.au> It's never too late to have a happy childhood.
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Well, I'm not. It seems like a decision made in haste.
Hardly.
Maybe I'll get used to it in a few decades, but right now I feel very disappointed. We were *so* close to agreeing on something nice, and then for some reason it all went pear-shaped. :-(
Not really. The contenders were: - [decorators] after the arguments. I really hate this, for good reasons which I won't repeat here. - [decorators] in front of the 'def'. For a while I really loved this, but several killer arguments were made against it, most having to do with the ambiguity, which confuses beginners. (A couple of people in the audience of my EuroPython keynote stood up and argued this with passion.) - Any number of variations on [decorators] before 'def', adding arbitrary mark-up to make it unambiguous. Including the 'as' keyword (which it isn't, by the way). All of which strike me as totally arbitrary. The 'as' keyword has a history of uses for renaming (e.g. in SQL and Python's import) but decorators are everything but renaming. - @decorators in front of 'def'. This is borrowed from Java (just like [decorators] was borrowed from C#) so minimizes invention. It isn't ambiguous, and as long as we're going to use arbitrary syntax we might as well use something that's familiar to at least one huge group of potential Python users. And yes, I'm not 100% comfortable with it either. But I know one thing: in this particular case, now is better than never. So I'm picking a solution everybody can hate equally. (What's wrong with pear-shaped, anyway? It's one of my favorite shapes. :-) --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/01aa7d6d4db83982a2f6dd363d0ee0f3.jpg?s=120&d=mm&r=g)
On Mon, 2004-08-02 at 23:51, Guido van Rossum wrote:
And yes, I'm not 100% comfortable with it either. But I know one thing: in this particular case, now is better than never. So I'm picking a solution everybody can hate equally.
(What's wrong with pear-shaped, anyway? It's one of my favorite shapes. :-)
So I conducted a little experiment, converting a bunch of modules that were using Python 2.3 compatible "post-processing" decorator syntax, to pie decorator syntax, so that I could get a more visceral reaction to the decision. For me, the short answer is: +1, and not just because "it's better than nothing". For longer functions, it's a clear win; the '@' stands out nicely, especially with the python-mode.el font-locking support I just added. :) It certainly exhibits all the benefits that motivated adding special syntax for decorators in the first place. For shorter functions, e.g. read-only accessors, my only (very minor) lament is that I can't compact the enter thing down to a single line. My fingers want to do something like: @property def get_bacon(self): return self._bacon but then I tell my fingers to do this instead: @property def get_bacon(self): return self._bacon Or, we'll compromise, my fingers and I, on: get_bacon = property(lambda self: self._bacon) So it's at least a wash there. (Really, pie decorators are better here too, IMO.) My only other minor lament has nothing to do with this specific syntax. I still wish there was a way to decorate multi-arg property()'s, but oh well. All in all, I'm quite happy with this syntax. Thanks Guido! -Barry
![](https://secure.gravatar.com/avatar/eaa875d37f5e9ca7d663f1372efa1317.jpg?s=120&d=mm&r=g)
At 02:01 PM 8/3/04 -0400, Barry Warsaw wrote:
My only other minor lament has nothing to do with this specific syntax. I still wish there was a way to decorate multi-arg property()'s, but oh well.
@property_getter def foo(self): ... @property_setter def foo(self,value): ... See Ed Loper's post at: http://mail.python.org/pipermail/python-dev/2004-April/043902.html and implementation at: http://www.cis.upenn.edu/~edloper/pydecorators.html
![](https://secure.gravatar.com/avatar/e70c1851e0679174014336e296f272b2.jpg?s=120&d=mm&r=g)
On Tue, 03 Aug 2004 14:01:42 -0400, Barry Warsaw <barry@python.org> wrote:
For longer functions, it's a clear win; the '@' stands out nicely, especially with the python-mode.el font-locking support I just added. :) It certainly exhibits all the benefits that motivated adding special syntax for decorators in the first place.
I think this is also a strong point for the '@' syntax. How should an editor know that a list before a method is a decoration and should be highlighted differently? The backwards compatibility to python < 2.4 doesn't count in my opinion, because other features like generators and list-comprehensions also can't be used in older pythons, and the old syntax with the decoration after the method body is still available, so this is no problem. +1 for the pie syntax from my little voice as a user of python Regards, Florian Schulze
![](https://secure.gravatar.com/avatar/03b7a4bd12e04741c5e42269b13846a1.jpg?s=120&d=mm&r=g)
Anthony Baxter <anthony@interlink.com.au> writes:
We're aiming for 2.4a2 this Thursday - so can people please hold off on checking into the trunk from Wednesday evening onwards, please.
Can someone have a look at http://www.python.org/sf/870382 ? I'm not at all sure how to address Martin's comments, and I'd like to see this in Python 2.4, in some form or other. Thanks, Paul -- Ooh, how Gothic. Barring the milk.
![](https://secure.gravatar.com/avatar/e2cb0083d4d61cebb1325281f88f3843.jpg?s=120&d=mm&r=g)
On Mon, Aug 02, 2004 at 06:06:09PM +0100, Paul Moore wrote:
Can someone have a look at http://www.python.org/sf/870382 ? I'm not at all sure how to address Martin's comments, and I'd like to see this in Python 2.4, in some form or other.
If you'd like to encourage examination of a bug or patch at the next bug day, you can add them to the 'bugs for examination' section of http://www.python.org/moin/PythonBugDayStatus. No guarantees, of course -- if the bug can only be reviewed by one person, and that person isn't around for the bug day, nothing much can be done -- but at least it'll draw some attention to them. (Will send an announcement for the next bug day shortly...) --amk
![](https://secure.gravatar.com/avatar/3acb8bae5a2b5a28f6fe522a4ea9b873.jpg?s=120&d=mm&r=g)
Paul Moore wrote:
Can someone have a look at http://www.python.org/sf/870382 ? I'm not at all sure how to address Martin's comments, and I'd like to see this in Python 2.4, in some form or other.
It slipped through my attention because it is a bug report, not a patch. I will look at it again soon. That said, I should continue to require that anybody desiring incorporation of a patch should review 10 other patches first. Regards, Martin
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so.
Thanks, Anthony! Especially thanks for thinking of updating the PEP. Jeremy reminded me last week that too often we're slacking on updating PEPs. The generator expressions PEP for example still doesn't reflect the current state of affairs. Maybe someone needs to put their foot down and require that PEPs are complete before features are checked in? --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Did the relative import syntax that was approved ever get checked in? I thought it was on the list of things to land in 2.4? --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/5a2d56afc1b00fb87dbe5e2387f0072f.jpg?s=120&d=mm&r=g)
Guido van Rossum wrote:
Did the relative import syntax that was approved ever get checked in? I thought it was on the list of things to land in 2.4?
Nope. The 2.4 release schedule PEP now lists this as lacking someone to drive it. I won't/can't spend time on it. So, if one of the people who wants it could step forward, that'd be excellent. Even if it's just to do the multi-line import syntax of from foo import ( bar, baz, bar2, baz2, bar3, baz3 ) -- Anthony Baxter <anthony@interlink.com.au> It's never too late to have a happy childhood.
![](https://secure.gravatar.com/avatar/b43e0157b16510f16fc567fc024eb6ef.jpg?s=120&d=mm&r=g)
Anthony Baxter <anthonyatinterlink.com.au> wrote:
Guido van Rossum wrote:
Did the relative import syntax that was approved ever get checked in? I thought it was on the list of things to land in 2.4?
Nope. The 2.4 release schedule PEP now lists this as lacking someone to drive it. I won't/can't spend time on it. So, if one of the people who wants it could step forward, that'd be excellent. Even if it's just to do the multi-line import syntax of
from foo import ( bar, baz, bar2, baz2, bar3, baz3 )
I took a stab at implementing this (the easy part of PEP 328--parens around import lists). Are the exact semantics of what's allowed documented somewhere? PEP 328 mostly talks about relative and absolute imports, and it doesn't specify the exact semantics of where parentheses should be allowed. My patch (attached) accepts import (os, sys) from sys import (stdin, stdout, stderr) import (os) from sys import (*) but rejects from (sys) import stdin import (os), (sys) import (os,) Should any of those be allowed? Anything that I missed? The patch is incomplete in other ways; the docs haven't been updated and neither have the parser module and compile package. If it's decided that it would be okay to include this separately from relative/absolute import support (they're different features, really), I'll complete the patch. Dima.
![](https://secure.gravatar.com/avatar/ecc9bee2b1efd190a4d9cb6f55d28a96.jpg?s=120&d=mm&r=g)
Dima Dorfman wrote:
I took a stab at implementing this (the easy part of PEP 328--parens around import lists). Are the exact semantics of what's allowed documented somewhere?
I think this syntax was originally proposed here: http://mail.python.org/pipermail/python-dev/2003-December/041072.html which mentions that since "a, b = c" is already equivalent to "(a, b) = c", so " in mind, I'd hand out the following scores (0=don't really care):
import (os, sys)
+0
from sys import (stdin, stdout, stderr)
+1
import (os)
+0
from sys import (*)
-0
from (sys) import stdin
-0
import (os), (sys)
-1
import (os,)
-1 </F>
![](https://secure.gravatar.com/avatar/ecc9bee2b1efd190a4d9cb6f55d28a96.jpg?s=120&d=mm&r=g)
I wrote:
which mentions that since "a, b = c" is already equivalent to "(a, b) = c", so " in mind, I'd hand out the following scores (0=don't really care):
JZ took control of my keyboard. sorry for that. the text above should have been: which mentions that since "a, b = c" is already equivalent to "(a, b) = c", so "from x import a, b" might as well made be equivalent to "from x import (a, b)". with that in mind, I'd hand out the following scores (0=don't really care) </F>
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
The 2.4 release schedule PEP now lists this as lacking someone to drive it. I won't/can't spend time on it. So, if one of the people who wants it could step forward, that'd be excellent. Even if it's just to do the multi-line import syntax of
from foo import ( bar, baz, bar2, baz2, bar3, baz3 )
I took a stab at implementing this (the easy part of PEP 328--parens around import lists).
Great!
Are the exact semantics of what's allowed documented somewhere?
Not unless it's in the PEP -- it usually takes a stab at implementing something to find what's left unspecified!
PEP 328 mostly talks about relative and absolute imports, and it doesn't specify the exact semantics of where parentheses should be allowed. My patch (attached) accepts
import (os, sys) from sys import (stdin, stdout, stderr) import (os) from sys import (*)
but rejects
from (sys) import stdin import (os), (sys) import (os,)
Should any of those be allowed? Anything that I missed?
This suggests (given the recent criticism of how we've been following the PEP process) that the PEP needs to be updated first. My own gut feeling is that it's not important to allow parentheses on "bare" (from-less) imports, since you can easily repeat the 'import' keyword on a new line; but that it is important on the from...import form, and then only after the "import" keyword. So that would accept your 2nd and 4th example but reject the 1st and 3rd. I guess one can argue about (*); I don't care about it and suggest that it be dropped.
The patch is incomplete in other ways; the docs haven't been updated and neither have the parser module and compile package. If it's decided that it would be okay to include this separately from relative/absolute import support (they're different features, really), I'll complete the patch.
Please do, and please use the SF patch manager to upload the patch. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/7e4e7569d64e14de784aca9f9a8fffb4.jpg?s=120&d=mm&r=g)
On Mon, Aug 09, 2004, Guido van Rossum wrote:
Dima Dorfman:
Are the exact semantics of what's allowed documented somewhere?
Not unless it's in the PEP -- it usually takes a stab at implementing something to find what's left unspecified!
Yup!
PEP 328 mostly talks about relative and absolute imports, and it doesn't specify the exact semantics of where parentheses should be allowed. My patch (attached) accepts
import (os, sys) from sys import (stdin, stdout, stderr) import (os) from sys import (*)
but rejects
from (sys) import stdin import (os), (sys) import (os,)
Should any of those be allowed? Anything that I missed?
This suggests (given the recent criticism of how we've been following the PEP process) that the PEP needs to be updated first.
Enh; as you say, implementation is often needed to clarify, and I don't think anyone would dispute that this is a small portion of the PEP.
My own gut feeling is that it's not important to allow parentheses on "bare" (from-less) imports, since you can easily repeat the 'import' keyword on a new line; but that it is important on the from...import form, and then only after the "import" keyword. So that would accept your 2nd and 4th example but reject the 1st and 3rd.
I guess one can argue about (*); I don't care about it and suggest that it be dropped.
I'd suggest that only ``from foo import (...)`` be permitted (where "..." does not include ``*``). But I don't care much, and I'll update the PEP as soon as it's clear which precise versions are allowed. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy@lion.austin.ibm.com
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
I'd suggest that only ``from foo import (...)`` be permitted (where "..." does not include ``*``). But I don't care much, and I'll update the PEP as soon as it's clear which precise versions are allowed.
This seems to be the consensus so far, so why don't you add all that detail to the PEP. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/b43e0157b16510f16fc567fc024eb6ef.jpg?s=120&d=mm&r=g)
Guido van Rossum <guido@python.org> wrote:
I'd suggest that only ``from foo import (...)`` be permitted (where "..." does not include ``*``). But I don't care much, and I'll update the PEP as soon as it's clear which precise versions are allowed.
This seems to be the consensus so far, so why don't you add all that detail to the PEP.
I just uploaded the updated patch as SF #1007189. That version is complete and, as agreed, only accepts the from/import form. It could use a good review, but otherwise it should be ready to go. Thanks, Dima.
![](https://secure.gravatar.com/avatar/e0ec20df0fae456afa4cfeb81725e42d.jpg?s=120&d=mm&r=g)
My own gut feeling is that it's not important to allow parentheses on "bare" (from-less) imports, since you can easily repeat the 'import' keyword on a new line;
It might not be strictly necessary, but for consistency I think it should be alllowed. By the way, rather than parentheses, I would prefer to be able to simply end the line with a comma and continue on to the next line: from Bubble import foo, spam, tomato, grail, arthur, camembert 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/7e4e7569d64e14de784aca9f9a8fffb4.jpg?s=120&d=mm&r=g)
My own gut feeling is that it's not important to allow parentheses on "bare" (from-less) imports, since you can easily repeat the 'import' keyword on a new line;
It might not be strictly necessary, but for consistency I think it should be alllowed.
Unless other support is forthcoming, this won't happen.
By the way, rather than parentheses, I would prefer to be able to simply end the line with a comma and continue on to the next line:
from Bubble import foo, spam, tomato, grail, arthur, camembert
Rejected earlier on parsing grounds. I've updated the PEP. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy@lion.austin.ibm.com
![](https://secure.gravatar.com/avatar/7e4e7569d64e14de784aca9f9a8fffb4.jpg?s=120&d=mm&r=g)
On Mon, Aug 02, 2004, Guido van Rossum wrote:
Did the relative import syntax that was approved ever get checked in? I thought it was on the list of things to land in 2.4?
Sorry, I've been slacking on driving it. What it really needs right now is someone to implement it. -- Aahz (aahz@pythoncraft.com) <*> http://www.pythoncraft.com/ "To me vi is Zen. To use vi is to practice zen. Every command is a koan. Profound to the user, unintelligible to the uninitiated. You discover truth everytime you use it." --reddy@lion.austin.ibm.com
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Did the relative import syntax that was approved ever get checked in? I thought it was on the list of things to land in 2.4?
Sorry, I've been slacking on driving it. What it really needs right now is someone to implement it.
It's not too late -- the decorator syntax quickly found someone who implemented the whole thing too. Hard to make a2, but a3 is still a possibility. --Guido van Rossum (home page: http://www.python.org/~guido/)
![](https://secure.gravatar.com/avatar/caacb731f9d4a5850385428ee0a5f954.jpg?s=120&d=mm&r=g)
Anthony Baxter wrote:
The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so.
In the mean time, can anyone give a pointer to where this was proposed or discussed? Jim -- Jim Fulton mailto:jim@zope.com Python Powered! CTO (540) 361-1714 http://www.python.org Zope Corporation http://www.zope.com http://www.zope.org
![](https://secure.gravatar.com/avatar/1efc90ff6075b7654d8a8ce6e51a2cd3.jpg?s=120&d=mm&r=g)
Jim Fulton <jim@zope.com> writes:
Anthony Baxter wrote:
The @decorator patch has been landed on the trunk, after getting the go-ahead from the BDFL. I'll update PEP-0318 with the final syntax in the next day or so.
In the mean time, can anyone give a pointer to where this was proposed or discussed?
AFAIK, in offline email (and occasionally on IRC, but that was mostly about implementation), presumably to avoid the thousands of emails cascade this subject inevitably seems to trigger. bike-shed-the-ultimate-ly y'rs mwh -- If a train station is a place where a train stops, what's a workstation? -- unknown (to me, at least)
![](https://secure.gravatar.com/avatar/047f2332cde3730f1ed661eebb0c5686.jpg?s=120&d=mm&r=g)
Jim Fulton <jim@zope.com> writes:
In the mean time, can anyone give a pointer to where this was proposed or discussed?
There are two slides in my EuroPython keynote (http://www.python.org/doc/essays/ppt/euro2004/euro2004.pdf) (pages 10 and 11) that mention it. It was discussion during and after this keynote that made me change my mind -- first I accepted that [deco] before def was unacceptable, then I found that @deco was not universally hated (Fredrik Lundh even liked it). --Guido van Rossum (home page: http://www.python.org/~guido/)
participants (32)
-
"Martin v. Löwis"
-
A.M. Kuchling
-
Aahz
-
Andrew McNamara
-
Anthony Baxter
-
Barry Warsaw
-
Bob Ippolito
-
David Abrahams
-
David Eppstein
-
Dima Dorfman
-
Fernando Perez
-
Florian Schulze
-
Fredrik Lundh
-
Greg Ewing
-
Guido van Rossum
-
James Y Knight
-
Jeremy Hylton
-
Jim Fulton
-
John J Lee
-
Jp Calderone
-
Mark Russell
-
Michael Hudson
-
Neil Schemenauer
-
Nick Coghlan
-
Nicolas Fleury
-
Paul Moore
-
Phillip J. Eby
-
Raymond Hettinger
-
Skip Montanaro
-
Terry Reedy
-
Tim Peters
-
Walter Dörwald