【发布时间】:2012-03-29 10:45:39
【问题描述】:
类的集合定义为:
class A():
@staticmethod
def call():
print('a')
class C(type):
def __repr__(self):
return 'somename'
class B(A):
__metaclass__ = C
@staticmethod
def call():
print('b')
def boundcall(self):
print('bound')
运行时报错:
TypeError: Error when calling the metaclass bases
a new-style class can't have only classic bases
我需要元类(我认为)在我的代码中具有 B 的已知字符串表示。这样做的原因是无关紧要的,但它将极大地帮助未来的更新。
所以假设我需要 C 作为 B 的元类,而 B 将是 A 的子类,有人可以告诉我这里出了什么问题以及我可以如何改变我正在做的事情来消除错误吗?
【问题讨论】:
标签: python oop typeerror new-style-class