Possible PEP: Improve classmethod/staticmethod syntax

Skip Montanaro skip at pobox.com
Wed Jun 4 05:53:57 CEST 2003

    Russ> Kevin Smith <Kevin.Smith at sas.com> wrote:
    >> A new proposed syntax for method modifiers is as follows:
    >> def classmethod foo(cls):
    >>   <code goes here>
    >> def staticmethod bar():
    >>   <code goes here>

    Russ> +1

    Russ> I think it's a great step forward for clarity.  

I don't believe Guido ever expected the current implementation of class and
static methods to be the final solution.  It's just that there were enough
possibile syntaxes that it wasn't immediately obvious which was the best.

>From time-to-time a more general function annotation syntax has been
proposed which would make the above unnecessary.  An optional list of
modifiers could be placed between the argument list and colon like so:

    def foo(cls) [class]:
      <code goes here>
    def bar() [static]:
      <code goes here>

That list could of course contain more than one element.

I don't see a PEP for the proposal, but I know it's come up a couple times.
You might try searching the python-dev archives for something like "function


More information about the Python-list mailing list