Metaclass of a metaclass

  • Thread starter Steven D'Aprano
  • Start date
S

Steven D'Aprano

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?

# Python 3.2


.... def __repr__(self):
.... s = super().__repr__()
.... return s.replace('class', 'metaclass')
........ pass
........ pass
....
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: object.__new__() takes no parameters



What am I doing wrong?
 
B

bruno.desthuilliers

Apparently it gives an error. Can anyone explain why this does not work?

# Python 3.2


...     def __repr__(self):
...             s = super().__repr__()
...             return s.replace('class', 'metaclass')


...     pass
(...)


...     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.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

Forum statistics

Threads
473,764
Messages
2,569,564
Members
45,041
Latest member
RomeoFarnh

Latest Threads

Top