Possible PEP: Improve classmethod/staticmethod syntax

Duncan Booth duncan at NOSPAMrcp.co.uk
Thu Jun 5 10:07:46 CEST 2003


Lulu of the Lotus-Eaters <mertz at gnosis.cx> wrote in 
news:mailman.1054745891.17181.python-list at python.org:

>|def Doc(docstring, **kw):
>|    def fDoc(f):
>|        f.__doc__ = docstring
>|        f.__dict__.update(kw)
>|        return f
>|class Klass(object):
>|    def meth(this, that) [Doc("Bob's your uncle.", Author="me")]:
>|        pass
> 
> I don't understand this version.  I see the idea that you want to pass
> arguments to the "function constructor"--but where does the name 'fDoc'
> come from?  How does 'Doc()' know to call 'fDoc()' (which I presume it
> wants to)?

That's because I missed out a line by mistake. Doc doesn't want to call 
fDoc, it wants to return it, so it should contain a 'return fDoc' 
statement.

-- 
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