Metaclass of a metaclass

bruno.desthuilliers at gmail.com bruno.desthuilliers at gmail.com
Tue Jun 5 11:30:57 EDT 2012


On Jun 5, 10:48 am, Steven D'Aprano <steve
+comp.lang.pyt... at pearwood.info> wrote:
> Apparently it gives an error. Can anyone explain why this does not work?
>
> # Python 3.2
>
> >>> class MyType(type):  # A metaclass...
>
> ...     def __repr__(self):
> ...             s = super().__repr__()
> ...             return s.replace('class', 'metaclass')
>
> >>> class Meta(metaclass=MyType):  # ... of a metaclass.
>
> ...     pass

(...)

> >>> class MyClass(metaclass=Meta):  # And now try to use it.
>
> ...     pass
> ...
> Traceback (most recent call last):
>   File "<stdin>", line 1, in <module>
> TypeError: object.__new__() takes no parameters
>
> What am I doing wrong?

Meta inherit from object, but being used as a metaclass, Meta.__new__
is called with name, bases, dict etc as arguments.




More information about the Python-list mailing list