私はプロパティを持つクラスに取り組んできましたが、pylint (0.25.1) で厄介な問題に遭遇しました。以下のコードでは、python 2.6 で導入されたプロパティを持つクラスを定義しています。メソッド内の は、aProperty という名前の定義済みメソッドを上書きします__init__
。self.aProperty
コンソールからの出力と pylint メッセージの出力も貼り付けました。
これは「pylint 開発者に報告してください」の場合ですか、それともこの (例の) コードは間違っていますか?
"""example module"""
class Example(object):
"""example class"""
@property
def aProperty(self):
"""get"""
print "using getter"
return self._myPropertyValue
@aProperty.setter
def aProperty(self, value):
"""set"""
print "using setter"
self._myPropertyValue = value
def secondPublicMethodToIgnorePylintWarning(self):
"""dummy"""
return self.aProperty
def __init__(self):
"""init"""
self._myPropertyValue = None
self.aProperty = "ThisStatementWillRaise E0202"
anExample = Example()
print anExample.aProperty
anExample.aProperty = "Second binding"
print anExample.aProperty
コンソール出力:
セッターの
使用 ゲッターの使用
ThisStatementWillRaise E0202
セッターの
使用 ゲッターの使用
2 番目のバインディング
Pylint 出力:
E0202: 7,4:Example.aProperty: テスト 1 行 26 で影響を受ける属性 このメソッドを隠す
E0202: 13,4:Example.aProperty: テスト 1 行 26 で影響を受ける属性 このメソッドを隠す