metaclasses

Raymond Hettinger vze4rx4y at verizon.net
Wed Jul 30 04:42:59 EDT 2003


> >> It seems this is a more general way to build classes than inheritance.
> >> Is this a reasonable viewpoint?

> > It is a less general way for building classes.
>
> Actually, the question doesn't make sense.  Metaclasses and
> inheritance are two different dimensions of generality.  Neither is
> more or less general than the other, because they generalize in
> different ways.
>
> However, his use of the built-in metatype 'type' is more general than
> the class statement, which seemed to be what he was asking.  One can
> supply a list of bases which, unlike the class statement, need not be
> a fixed length.  In fact, the bases can be calculated dynamically.
> Likewise with the class dict.

I read his question as asking about the merits
of subclassing type vs using type() directly.

class MyMeta(type):
      . . .
class MyClass:
    __metatype__ = MyMeta
      . . .

vs.

MyClass = type(n, b, d)



Raymond Hettinger








More information about the Python-list mailing list