
Tim Peters <tim.one@home.com>:
"class methods" in *this* thread is being used in a Smalltalk sense (because it's Thomas Heller's thread, and he made clear that he doesn't want C++-style class statics).
Well, I shouldn't have talked about C++ static methods, because I'm not too familiar with them. Here's what I want: Assume C is a class with a class-method mth, and D is 'class D(C): pass'. C.mth() should call this method, which in turn (automatically) receives C itself as the first parameter. D.mth() should call this method, which in turn (automatically) receives D itself as the first parameter.
It sounds like he wants not just class methods, but to unify classes and instances the way they are in Smalltalk.
The metaclass approach is one solution, not neccessarily the best.
That's not necessary *just* to get class methods. For instance, suppose you could write
class Foo:
def ftang(class c, x, y, z); ...
where the 'class' keyword in the argument list would say that it is to be a class method. That special form of the def statement would create an 'unbound class method' object, whose first argument would be filled in with the class object when Foo.ftang was accessed.
Donald Beaudry's objectmodule uses the metaclass hook to provide class methods. I like the resulting syntax very much: He uses an 'inner class' with the special name '__class__' to specify class methods: class Object(object.base): class __class__: def class_method(self): pass def normal_method(self): pass If I understand correctly (objectmodule does not run under 1.5.2 or later), an instance of __class__ will become the metaclass of Object, and __class__'s methods will become class methods of Object. I've played a little bit with metaclasses in pure python (it is faster this way), and have an implementation with the same syntax where __class__ is never instantiated, and simply acts as a function container. Addendum: Additionaly to class methods, I would like to have 'magic' class methods, maybe named __class_init__ and __class_getattr__. Easy to guess what they should do...
Hmmm... might write a PEP on that!
Me too. Thomas