我正在以这种方式实现复合模式:
1)“抽象”组件是:
class Component(object):
"""Basic Component Abstraction"""
def __init__(self, *args, **kw):
raise NotImplementedError("must be subclassed")
def status(self):
"""Base Abstract method"""
raise NotImplementedError("must be implemented")
2) 一片叶子:
class Leaf(Component):
"""Basic atomic component
"""
def __init__(self, *args, **kw):
self.dict = {}
def status(self):
"""Retrieves properties
"""
return self.dict
问题是 pylint 当然会产生这个警告:
Leaf.__init__: __init__ method from base class 'Component' is not called
但在我的叶子中,我不能要求:
def __init__(self, *args, **kw):
Component.__init__(self, *args, **kw)
self.dict = {}
没有引发异常。
我必须忽略 pylint 警告还是编码错误?