通常情况下,子类一类我这样做如何继承ABCMeta
class Subby(Parenty):
def __init__(self):
Parenty.__init__(self)
但现在我想继承元类,具体ABCMeta,所以我在做
import ABCMeta
class Subby(ABCMeta):
def __init__(self):
ABCMeta.__init__(self) #this never seems to run
def __new__(mcls, name, bases, namespace):
cls = ABCMeta.__new__(mcls, name, bases, namespace)
return cls
但是,当我再尝试继承Subby
为元类像
class newClass(metaclass=Subby):
pass
我得到的错误TypeError: __init__() takes 1 positional argument but 4 were given
。
这是为什么,以及如何正确地继承ABCMeta?
'__init__'需要采用'__new__'相同的参数。 – user2357112
你可以自己实例化Subby吗? –
'ABCMeta'是'abc.ABCMeta'类还是另一个在另一个模块中定义的类? – slackmart