
"Thomas Heller" <thomas.heller@ion-tof.com> wrote,
Donald Beaudry's objectmodule uses the metaclass hook to provide class methods. I like the resulting syntax very much:
Thank you. I like it too, especially because MyClass.__class__ returns what *I* would expect ;) and the source reflects that too.
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.
That's correct. I currently use objectmodule on 1.5.2. I would not be surprised if it doesnt work on newer versions though as I have never tried it there. Perhaps you found an out-of-date version, or perhaps I never sent out a newer version. Regardless, I'd be happy to get you a version that works with 1.5.2 (or upload one somewhere for more public consumption)
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.
Ah but with the object module, it does get instantiated. In fact, __class__ is derived (implicitly) from the __class__ of the containing base class. Inheritance works as expected.
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...
Objectmodule provides for that as well. Just define __init__, __getattr__, etc., inside the __class__ definition. There is even and __new__ which is responsible for controling the "memory allocation" of instances. This is useful for, amoung other things, singletons.
Hmmm... might write a PEP on that!
Me too.
...gone are the days when a simple email to Guido was all it took to get a proposal going ;) -- Donald Beaudry Ab Initio Software Corp. 201 Spring Street donb@init.com Lexington, MA 02421 ...So much code, so little time...