いくつかの型を変更する再利用可能なクラスにいくつかのコードがあります。ここに簡略化されたバージョンがあります。
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()
この新しい関数を使用するすべてのクラスは懲らしめられ、すべての参照でメッセージを無効にする必要があります。このクラスに不明な参照がある場合に、Pylint にチルするように指示するコードを API に追加したいと思います。
悲しいかな、pylint のドキュメントは...うーん...私の理解に資する品質ではなく、そこに提案を見つけることができませんでした。
要約すると、クライアントが参照するたびに、このクラスに関連する E1101 ルールをオフにするように API コードで pylint に指示できますか? 別の解決策はありますか?