Possible PEP: Improve classmethod/staticmethod syntax

Andrew Bennetts andrew-pythonlist at puzzling.org
Wed Jun 4 00:31:11 EDT 2003


On Wed, Jun 04, 2003 at 04:09:33AM +0000, Bryan wrote:
> 
> ok, i understand what you mean now.  but, in a way, it seems that we are
> playing symantec games here. from a programmers prespective, it looks and
> feels like a keyword.
> 
> style 1:
> def myMethod(args) [staticmethod]:
>     blah, blah, blah
> 
> style 2:
> def staticmethod myMethod(args):
>     blah, blah, blah
> 
> 
> these two "styles" appear to be the same, except the second one seems to be
> more natural and simpler and obvious to me. the first one looks like "the
> function is becoming an array or indexed or something... not sure exactly
> what those [] mean... better look it up in that nutshell book....".   sorry,
> but i have to vote -1 on style one, +1 on style 2, +0 keeping it the way it
> is.

Where the [] proposal shines, though is when using multiple wrappers for the
function:

    def myMethod(cls, args) [staticmethod, synchronised]:
        "blah, blah, blah"

(Here synchronised is a hypothetical function that ensures access to the
function it wraps is serialised)

Which would be equivalent to:

    def myMethod(cls, args):
        "blah, blah, blah"
    myMethod = staticmethod(synchronised(myMethod))

(Or possibly nested the other way; I haven't thought deeply about which way
works better).

-Andrew.






More information about the Python-list mailing list