私はプロパティを持つクラスで作業していましたが、pylint(0.25.1)で厄介な問題に遭遇しました。以下のコードでは、Python 2.6で導入されたプロパティを持つクラスを定義しています。 しかし、 __init__
メソッドself.aProperty
では、aPropertyという定義済みのメソッドを上書きするという事実があります。私はコンソールからの出力とpylintメッセージの出力も貼り付けました。Pylint E0202 False Positive?あるいは、このコードは間違っていますか?
これは「pylint devsに報告してください」のケースですか、このコード例が間違っていますか?
"""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
を使用してセッター
を使用して
NT出力:
E0202:7,4:Example.aProperty:test1のライン26非表示に影響を受けた属性は、この方法
E0202:13,4:Example.aProperty:属性がtest1のライン26非表示にこの影響を受け方法
をPB私はあなたのコードに問題が表示されていない - 多分あなたはそれを報告しなければなりません。 – aquavitae