class meta(type):
mros = (object,)
def __new__(metacls, name, bases, namespace, fake_bases=()):
print('entering __new__')
metacls.fake_bases = fake_bases
cls = type.__new__(metacls, name, bases, namespace)
print('exiting __new__')
return cls
@staticmethod
def mro(*args):
print('entering mro')
return meta.fake_bases + (object,)
class a(metaclass=meta, fake_bases=()): pass
That puts out the error message:
entering meta.__new__
entering meta.mro
Traceback (most recent call last):
File "<pyshell#5948>", line 1, in <module>
exec(code, u)
File "<string>", line 14, in <module>
File "<string>", line 6, in __new__
TypeError: super(type, obj): obj must be an instance or subtype of type
That doesn't at all explain why it doesn't work because super was never explicitly called. If the argument fake_bases isn't empty, or if mro isn't made a staticmethod/classmethod, it returns an appropriate message
TypeError: mro() returned base with unsuitable layout ('tuple')
|