我需要创建一个类,根据某些条件使用不同的基类。对于某些类,我得到了臭名昭著的:
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
sqlite3
是一个模块而不是一个“类”。 - agf