why is there no class (static) methods in Python ?

Thomas Heller thomas.heller at ion-tof.com
Tue Jun 19 07:56:11 EDT 2001


<James_Althoff at i2.com> wrote in message news:mailman.992898207.28586.python-list at python.org...
> My own metaclass experiments and posts have all tried to provide a
> mechanism for true class methods.  But all metaclass mechanisms in Python
> that I'm familiar with are awkward, IMHO -- and probably don't and won't
> get used much (if at all).
I'm really satisfied with the following recipe (you will probably
remember):

class ClassMeta:
    class Instance:
        def __init__(self, ...):
            # initialize the new instance
            ....

        def inst_method(self):
            # an instance method

    def new(self, *args):
        # a class method acting as a constructor
        return self.Instance(arg1, arg2):

    def a_class_method(self, ...):
        # another class method
        ....


Class = ClassMeta()

It is easy to understand and simulates 'real' class methods very well.
I will certainly use them.

What's wrong with this pattern?

>  As far as the class/type healing work that is
> underway: I hope class methods will be a part of it.  But so far the
> messages from Guido that I've seen indicate that though the class/type
> healing is a high priority, true class methods as a part of said healing
> are not necessarily important (to him).  So I'm not optimistic.
Even if class methods would be on the list, how would/should the syntax be
to create them?

Thomas

PS: Maybe you've seen Don Beaudry's objectmodule which also provides
class methods (via a C-extension). He uses a syntax very similar to
the above: He defines the normal (instance) methods in the outer
class, and the class methods in a nested class (Should I say 'inner'
class?)





More information about the Python-list mailing list