我在修改某些類型的可重用類中有一些代碼。這是一個簡化版本。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