我目前正在为 python 2 开发,我正在尝试使用抽象基类来模拟接口。我有一个接口、该接口的基本实现以及许多扩展基本实现的子类。它看起来像这样:
class Interface(object):
__metaclass__ = ABCMeta
class IAudit(Interface):
@abstractproperty
def timestamp(self):
raise NotImplementedError()
@abstractproperty
def audit_type(self):
raise NotImplementedError()
class BaseAudit(IAudit):
def __init__(self, audit_type):
# init logic
pass
@property
def timestamp(self):
return self._timestamp
@property
def audit_type(self):
return self._audit_type
class ConcreteAudit(BaseAudit):
def __init__(self, audit_type):
# init logic
super(ConcreteAudit, self).__init__(audit_type)
pass
但是 PyCharm 通知我ConcreteAudit
应该实现所有抽象方法。但是,BaseAudit
(未指定为 abc)已经实现了这些方法,并且ConcreteAudit
是BaseAudit
. 为什么 PyCharm 会警告我?它不应该检测到IAudit
的合同已经通过 执行了BaseAudit
吗?