This issue tracker has been migrated to GitHub, and is currently read-only.
For more information, see the GitHub FAQs in the Python's Developer Guide.

classification
Title: Better error message when failing to overload metaclass.mro
Type: enhancement Stage:
Components: Interpreter Core Versions: Python 3.7
process
Status: open Resolution:
Dependencies: Superseder:
Assigned To: Nosy List: bup
Priority: normal Keywords:

Created on 2017-10-15 00:34 by bup, last changed 2022-04-11 14:58 by admin.

Messages (1)
msg304406 - (view) Author: Dan Snider (bup) * Date: 2017-10-15 00:34
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')
History
Date User Action Args
2022-04-11 14:58:53adminsetgithub: 75970
2017-10-15 00:34:04bupcreate