我在修改某些类型的可重用类中有一些代码。这是一个简化版本。
class Foo:
def __init__(self):
self.count = 0
def increment(self):
self.count += 1
# Add another method outside of the class definition.
# Pylint doesn't care about this, and rates this file 10/10.
Foo.__dict__["current_count"] = lambda self: self.count
在实际代码中,“current_count”是一个变量,而不是一个固定的字符串,这就是我没有写的原因:
Foo.current_count = lambda self: self.count # Cannot do in my scenario.
现在,当我的客户开始使用新功能时,皮林特惊恐地跳上跳下。
import server_api
def main():
foo_count = server_api.Foo()
foo_count.increment()
print foo_count.current_count()
# Pylint complains here:
# E1101: 8:main: Instance of 'Foo' has no 'current_count' member
# I don't want to have to tell pylint to disable that message in every client.
main()
每个使用这个新函数的类都会受到惩罚,我被迫在每个引用中禁用该消息。我宁愿在 API 中添加一些代码,以告诉 Pylint 在此类上有未知引用时冷静下来。
唉,pylint 文档是......嗯......质量不利于我的理解,我一直无法在那里找到任何建议。
所以归结为:每当客户引用它时,我可以在我的 API 代码中告诉 pylint 关闭与此类相关的 E1101 规则吗?还有其他解决方案吗?