Static method and class method comments

Tom Good Tom_Good1 at excite.com
Thu Jul 26 12:04:34 EDT 2001


Kevin.Smith at sas.com (Kevin Smith) wrote in message news:<9jn382$lqf$1 at license1.unx.sas.com>...

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

[snip]

I would also use the fact that 'foo' has no 'self' parameter as a clue
that it is a class method.  I realize that naming it 'self' is an
artificial convention, but it is followed so often that I feel pretty
safe using it as an at-a-glance guideline.


Tom



More information about the Python-list mailing list