static methods

Clark C. Evans cce at clarkevans.com
Fri Mar 23 16:51:10 EST 2001


I was wondering if there is any rationale as to why 
Python classes do not have static methods?  

I was also wondering if it would make sence to allow
None to be used as self?  For example:

    class MyClass:
        def myStatic(static, str): print str
 
    MyClass.myStatic(None,'my-first-argument')

Why would you want to do this?  Let's say I want
a "check" method, which checks to see if an object
from another class can "pass off" as an object
in the current class (see Paul Prescod's work
on the type special interest group list).

    class MyClass:
        def func(str): print str
        def __check__(static,obj):
            if getattr(obj,"func"): return obj
            return None

    class LikeMyClass:
        def func(str): print str


    x = LikeMyClass()
    MyClass.__check__(None,x)

Anyway... how problematic is allowing None to be used
in "unbound" methods in order to 'simulate static methods?

Thanks!

Clark






More information about the Python-list mailing list