我在修改某些类型的可重用类中有一些代码。这是一个简化版本。API可以告诉Pylint不要在客户端代码中抱怨吗?
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.
现在,当我的客户来使用新功能,Pylint在恐怖中上下跳动。
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文档是... ummm ...没有质量有利于我的理解,我一直无法找到任何建议。
所以煮沸:我可以告诉pylint在我的API代码中关闭与此类相关的E1101规则,只要客户端引用它?还有其他解决方案吗?
我沉默了很多Pylint的投诉,这对我来说也是一个有趣的问题。 – Eike 2010-08-18 07:13:37