[Python-Dev] method decorators (PEP 318) (original) (raw)

Shane Holloway (IEEE) shane.holloway at ieee.org
Tue Mar 30 01:16:04 EST 2004


Greg Ewing wrote:

"Shane Holloway (IEEE)" <shane.holloway at ieee.org>:

def foo(self, *args) [methodreturns(float)] + IMyProtocolMethod: pass # Code goes here Under the current proposal, that wouldn't be allowed. You'd need a helper function of some sort that turned a list of decorators into a single decorator: def foo(self, *args) [methodreturns(float), decoratorlist(IMyProtocolMethod)]: or, using the extension I proposed a while back, def foo(self, *args) [methodreturns(float), *IMyProtocolMethod]:

I think that reads the best, but then I'd start to want it with normal lists, too. ;)

And I did think of the decoratorlist work-around, but I hadn't thought that you could just as easily do the following:

 class Example(object):
     IMyProtocolMethod = decoratorlist(
         synchronized(lock),
         attributes(author='SWH', protocol=IMyProtocol),
         myArgumentWireMarshaller)

     def foo(self, *args) [methodreturns(float), IMyProtocolMethod]:
         pass # Code goes here
     def bar(self, *args) [methodreturns(str), IMyProtocolMethod]:
         pass # Code goes here
     def baz(self, *args) [methodreturns(int), IMyProtocolMethod]:
         pass # Code goes here

Which makes me just as happy again. :) I hope you all had a good time at PyCon. One of these years I look forward to meeting all of you.

Cheers, -Shane Holloway

p.s. sorry for the repeat Greg ;)



More information about the Python-Dev mailing list