ClassName.attribute vs self.__class__.attribute

Hrvoje Niksic hniksic at
Thu Jun 12 14:50:40 CEST 2008

Duncan Booth <duncan.booth at invalid.invalid> writes:

> In fact, thinking about it a bit more, I think that if you did have
> another metaclass which is its own metaclass then the class cannot
> subclass 'object'.

You could if the metaclass of your metaclass inherited from 'type'.
Then your types could still be binary-compatible with Python types,
and your objects with 'object'.  It's difficult to envision what you'd
gain with a custom meta-meta-class, but it seems possible:

>>> class MetaMeta(type): pass
>>> class Meta(type):
...   __metaclass__ = MetaMeta
>>> class Foo(object):
...   __metaclass__ = Meta
>>> f = Foo()
>>> f
<__main__.Foo object at 0xb7d27bec>
>>> type(f)
<class '__main__.Foo'>
>>> type(type(f))
<class '__main__.Meta'>
>>> type(type(type(f)))
<class '__main__.MetaMeta'>
>>> isinstance(f, object)

More information about the Python-list mailing list