[New-bugs-announce] [issue31789] Better error message when failing to overload metaclass.mro
Dan Snider
report at bugs.python.org
Sat Oct 14 20:34:04 EDT 2017
New submission from Dan Snider <mr.assume.away at gmail.com>:
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')
----------
components: Interpreter Core
messages: 304406
nosy: bup
priority: normal
severity: normal
status: open
title: Better error message when failing to overload metaclass.mro
type: enhancement
versions: Python 3.7
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue31789>
_______________________________________
More information about the New-bugs-announce
mailing list