我需要根据某些条件创建一个使用不同基类的类。在一些课程中,我得到了臭名昭著的:
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases
一个例子是sqlite3
,这里有一个简短的例子,你甚至可以在解释器中使用:
>>> import sqlite3
>>> x = type('x', (sqlite3,), {})
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
TypeError: metaclass conflict: the metaclass of a derived class must be a (non-strict) subclass of the metaclasses of all its bases