亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

如何禁用任何使用我的函數的 pylint 檢查?

如何禁用任何使用我的函數的 pylint 檢查?

開心每一天1111 2023-03-16 09:05:41
我制作了一個classproperty描述符,每當我使用用它裝飾的函數時,我都會收到多個pylint檢查錯誤。這是一個帶有示例裝飾函數的示例類:class Bar:    """    Bar documentation.    """    # pylint: disable=no-method-argument    @classproperty    def foo():        """        Retrieve foo.        """        return "foo"多虧了描述符,我可以調用Bar.foo并獲取返回的字符串foo。不幸的是,每當我將這樣的函數用于稍微復雜的項目(例如返回對象實例的函數)時,pylint就會開始抱怨諸如no-memberor之類的東西unexpected-keyword-arg,僅僅是因為它認為Bar.foo是一個方法,而不是一個包裝的classproperty對象。我想禁用任何使用我的函數的代碼的警告- 我絕對不能允許# pylint: disable每次使用classproperty-wrapped 方法時都必須編寫。我該怎么做呢pylint?或者也許我應該改用其他 linter?以下是由于上述原因生成的警告示例:class Bar:    """    Bar documentation.    """    # pylint: disable=no-method-argument    @classproperty    def foo():        """        Retrieve an object.        """        return NotImplementedError("Argument")print(Bar.foo.args)pylint抱怨E1101: Method 'foo' has no 'args' member (no-member)(即使我知道它肯定有),我想完全禁用任何使用Bar.foo.args或類似的模塊/類/函數的警告。對于任何感興趣的人,這里是描述符的最小實現classproperty:class classproperty:    """    Minimal descriptor.    """    # pylint: disable=invalid-name    def __init__(self, func):        self._func = func    def __get__(self, _obj, _type):        return self._func()
查看完整描述

2 回答

?
慕村225694

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很好。


查看完整回答
反對 回復 2023-03-16
?
婷婷同學_

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,也應該是可行的。



查看完整回答
反對 回復 2023-03-16
  • 2 回答
  • 0 關注
  • 118 瀏覽
慕課專欄
更多

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號