Possible PEP: Improve classmethod/staticmethod syntax

Duncan Booth duncan at NOSPAMrcp.co.uk
Wed Jun 4 16:16:26 CEST 2003


Duncan Booth <duncan at NOSPAMrcp.co.uk> wrote in 
news:Xns93907DB5984EBduncanrcpcouk at 127.0.0.1:

> Lulu of the Lotus-Eaters <mertz at gnosis.cx> wrote in 
> news:mailman.1054701247.26488.python-list at python.org:
> 
>> But you could also write your own function, and use it in a
>> metaclass-like way, e.g.:
>> 
>>     def fooDoc(f):
>>         f.__doc__ = "Bob's your uncle."
>>         return f
>> 
>>     class Klass(object):
>>         def meth(this, that) [fooDoc]:
>>             pass
>> 
> 
> Or better:
> 
> def Doc(docstring, **kw):
>     def fDoc(f):
>         f.__doc__ = docstring
>         f.__dict__.update(kw)
>         return f
      return fDoc
> 
> class Klass(object):
>     def meth(this, that) [Doc("Bob's your uncle.", Author="me")]:
>         pass

I hate posting untested code, its always wrong.


-- 
Duncan Booth                                             duncan at rcp.co.uk
int month(char *p){return(124864/((p[0]+p[1]-p[2]&0x1f)+1)%12)["\5\x8\3"
"\6\7\xb\1\x9\xa\2\0\4"];} // Who said my code was obscure?




More information about the Python-list mailing list