[Python-Dev] Class Methods

Thomas Heller thomas.heller at ion-tof.com
Wed Apr 25 03:28:25 EDT 2001


> > [...] The problem is that normally
> > metaclasses are implemented in C (it seems a python
> > implementation is way to slow for most uses). On the
> > other hand this is a lot of work, you have to completely
> > duplicate the whole class/instance/method behaviour
> > from standard python.
> But I can use the functions that Python would use to build one of
> its classes, just add an additional initialization call
> after that....

How that? I didn't succeed to use new.instancemethod()
on a metaclass instead of MetaMethodWrapper (from demo/metaclasses/meta.).

>
> Furthermore, speed seems not fundamental for meta classes.
> When is a meta class used? To create a class.
> One does not tend to do that too often....

It's also used to implement additional behaviour for the instances.
Just did a little test (also using demo/metaclasses/meta.py here):

Calling 'print x' when x is an instance of 'class C(Meta): pass'
seems to be slower by a factor of about 50 (!) compared to an
instance of a 'normal' python class.

This will become much worse if there is a deep inheritance
relation.

Thomas





More information about the Python-list mailing list