Re: [python-uk] Advice on decorator grammar

2013-04-08 Thread Simon Yarde
Thanks Sven. That's just what I was looking for. For anyone interested, here is the message with Guido's gut-feeling back in 2004, and the in the subsequent few posts are arguments one way or the other: http://mail.python.org/pipermail/python-dev/2004-August/046711.html In summary, there is a d

Re: [python-uk] Advice on decorator grammar

2013-04-05 Thread Sven Marnach
Guido actually gave approval for a change to allow aribtrary expressions after the @ (about two years ago on python-ideas). There's also some bug about this on the tracker. (I can't be bothered to look up the links...) Cheers, Sven ​ ___ python-uk

Re: [python-uk] Advice on decorator grammar

2013-04-05 Thread Stestagg
I've been thinking about this, and the more I see, the more I'm convinced that this extra gramma would *not* help with generating 'pythonic' code. Having used decorators as: wrappers, subsituters, dynamic substituters, dependency injectors, actual decorators and other things (several of these were

Re: [python-uk] Advice on decorator grammar

2013-04-04 Thread Simon Yarde
Thanks Nick. I wonder if you see any use or validity in an expanded grammar allowing class-initialisation within the decorator syntax? Or as Stestagg suggests, there is no real practical need for it? > decoratedfoo.orig(1, 2) # run original function Thanks for highlighting decorato

Re: [python-uk] Advice on decorator grammar

2013-04-04 Thread Nick Murdoch
Hi Simon, It might be of use to you to know that the decorator syntax is actually a syntactic shortcut for a longer way of writing the same thing. For instance, @mydecorator def foo(a, b): pass is identical to def foo(a, b): pass foo = mydecorator(foo) If you wanted to only apply th

Re: [python-uk] Advice on decorator grammar

2013-04-03 Thread Simon Yarde
This may well be moot, so thank you for chipping in. All your suggestions are completely valid and practical. And thank you Stestagg and a.cavallo for commenting on references; I've tried to show in the examples below how the instance might be used to store config that is accessed by instance-

Re: [python-uk] Advice on decorator grammar

2013-04-03 Thread Stestagg
Technically, you don't have to worry about refcounts here. evaluating 'AClass().method' results in a 'bound' method. The method binding contains a reference to the instance, so internally, a reference is always held. It does mean however that the AClass instance is anonymous, there is no simple

Re: [python-uk] Advice on decorator grammar

2013-04-03 Thread a . cavallo
My first tought would be the mydecorator = MyDecorator() will hold the object instance reference and the ref count won't go to zero.. So.. Decorator grammar is this: decorator: '@' dotted_name [ '(' [arglist] ')' ] NEWLINE The grammar prevents this: class MyDecorator: ... def dec

Re: [python-uk] Advice on decorator grammar

2013-04-03 Thread Stestagg
This seems redundant to me, the MyDecorator instance would not be bound to anything, so you'll 'loose' the reference to it, except through the call to decorator_method(). You could do this by making decorator_method a classmethod: class MyDecorator(object): @classmethod def decorate_this

[python-uk] Advice on decorator grammar

2013-04-03 Thread Simon Yarde
Hi All I've not posted to this list before. Hello! I have a question about decorators and have failed to devise a search that has thrown up any history of discussion on this particular matter. Does the following seem like something that 'should' work? Or is anyone aware of a source of document