Metaclass of a metaclass

Ian Kelly ian.g.kelly at gmail.com
Tue Jun 5 06:39:49 EDT 2012


On Tue, Jun 5, 2012 at 2:48 AM, Steven D'Aprano
<steve+comp.lang.python at pearwood.info> wrote:
> I was playing around with metaclasses and I wondered what would happen if
> the metaclass itself had a metaclass. Sort of a metametaclass.
>
> Apparently it gives an error. Can anyone explain why this does not work?

In your example, Meta is not actually a metaclass, as it inherits from
object, not type.  Here's an example that works:

>>> class MetaMeta(type): pass
...
>>> class Meta(type, metaclass=MetaMeta): pass
...
>>> class MyClass(metaclass=Meta): pass
...

Anyway, metaclasses of metaclasses is not that unusual, as type is
already its own metaclass.

Cheers,
Ian



More information about the Python-list mailing list