Re: Metaclass of a metaclass



On Jun 5, 10:48 am, Steven D'Aprano <steve
+comp.lang.pyt...@xxxxxxxxxxxxx> 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.

.



Relevant Pages

  • Re: Multiprocessing bug, is information ever omitted from a traceback?
    ... for which Python 2.7.2 is the default Python version. ...     self.run ... expected string or Unicode object, ... Here's the traceback that I obtained tonight. ...
    (comp.lang.python)
  • Re: "Ayatollas" crack down on Internet
    ... below were articulated by Steve (like the question of whether or not ...     a- As he notes, ... The rule "dina de-malkhuta dina" (The law of the land is the law ... the various haredi communities were ...
    (soc.culture.jewish.moderated)
  • Steve Urbanowicz, a Tribute
    ... Steve was never afraid to tell you what he thought or what he saw. ... Coney Island Thunderbolt being destroyed. ... Coney Island, City of Fire ...   The lift hill structure was torn apart and removed. ...
    (rec.roller-coaster)
  • Re: "Ayatollas" crack down on Internet
    ... below were articulated by Steve (like the question of whether or not ... We all know he is intentionally comparing the chareidi rabbinate ...     a- As he notes, ...
    (soc.culture.jewish.moderated)
  • Re: Rudeney: I have an answer for you stranger -
    ...    but left it to the reader own determination. ... seen Amanda and me together at the same time (because we have ... You will either knee jerk like a womb baby, in which case my time on you ... what you don't realize is that Steve and I are online friends ...
    (rec.arts.disney.parks)