Static method and class method comments

Kevin Smith Kevin.Smith at sas.com
Wed Jul 25 14:30:25 EDT 2001


I am very glad to see the new features of Python 2.2, but I do have a minor 
gripe about the implementation of static and class methods.  My issue stems 
from the fact that when glancing over Python code that uses static or class 
methods, you cannot tell that a method is a static or class method by looking 
at the point where it is defined.  Here is the example given on the Python web 
site.

class C:
        def foo(x, y):
            print "classmethod", x, y
        foo = classmethod(foo)

It is clear that 'foo' is a class method simply because the classmethod() call 
is only two lines away.  It is not so clear when 'foo' is a 100 line method. 
This implementation really doesn't fit the clean, concise syntax of Python 
that I've come to love (and expect).  I would very much prefer something along 
the lines of 

class C:
        classdef foo(x, y):
            print "classmethod", x, y

This syntax indicates very clearly at the time of definition whether the 
method is an instance method or a class method.  A similar syntax could also 
be used for static methods.  I am very happy to see class methods and static 
methods in Python, but, to me, the current implementation still has that 
"workaround look" to it.

Kevin Smith
Kevin.Smith at sas.com



More information about the Python-list mailing list