2 回答

TA貢獻1880條經驗 獲得超4個贊
我設法通過將項目類型提示為以下內容來創建一個骯臟的黑客None:
class Bar:
"""
Bar documentation.
"""
# pylint: disable=no-method-argument,function-redefined,too-few-public-methods
foo: None
@classproperty
def foo():
"""
Retrieve an object.
"""
return NotImplementedError("Argument")
我寧愿避免使用這樣的代碼,因為由于循環導入問題(因此None),我實際上無法導入應該進行類型提示的項目,但它的技巧pylint很好。

TA貢獻1844條經驗 獲得超8個贊
據我所知,這是不可能的。
我還沒有找到在pylint的配置中解決這個問題的方法。我能找到的最接近的是選項property-classes,但它只影響invalid-name檢查器,所以不是我們在這里尋找的:
:property-classes:
List of decorators that produce properties, such as abc.abstractproperty. Add
to this list to register other decorators that produce valid properties.
These decorators are taken in consideration only for invalid-name.
Default: ``abc.abstractproperty``
也許這是一個值得直接詢問pylint的開發人員的問題。
在我看來,它可以通過轉換插件來解決(也許這是為了靈感?)。Pylint可以很好地處理@property
裝飾器,所以像這里建議的那樣@classproperty
,也應該是可行的。
添加回答
舉報