如何禁用pylint禁止自用警告?

How to disable pylint no-self-use warning?

我在 Python3 中编码并使用 pylint 来保持我的代码整洁。

我想定义类似接口 class 的东西,这样我就可以以简洁明了的方式添加更多功能,但是,pylint 妨碍了这个目标。

这是一个示例方法:

def on_enter(self, dummy_game, dummy_player): #pylint disable=no-self-use
    """Defines effects when entering area."""
    return None

这是 pylint 输出:

R: 70, 4: Method could be a function (no-self-use)

问题是:

  1. 如何抑制警告(注意 #pylint 注释)?或
  2. 如何告诉 pylint 这只是一个接口(注意 dummy_gamedummy_player

编辑: pylint --version 的输出:

pylint 1.2.1, 
astroid 1.1.1, common 0.61.0
Python 2.7.8 (default, Oct 20 2014, 15:05:19) 
[GCC 4.9.1]

您目前忽略此为

def on_enter(self, dummy_game, dummy_player): #pylint disable=no-self-use
    ...

改为

# pylint: disable=R0201
def on_enter(self, dummy_game, dummy_player): 
    ...

向您的文件添加如下评论

# pylint: disable=R0201

您可以在 documentation here 上找到每个 warnings/errors 的短代码助记符:

no-self-use (R0201):

Method could be a function Used when a method doesn’t use its bound instance, and so could be written as a function.

如果整个文件仅包含界面代码,您可以将其放在顶部:

# pylint: disable=R0201
class SomeInterface(object):
    ...
    ...

如果您还有其他代码,并且只想为接口 class 禁用此功能,您可以像

一样再次启用检查
# pylint: disable=R0201
class SomeInterface(object):
    ...
    ...

# pylint: enable=R0201

class AnotherClass(object):
    ...
    ...

原来我缺少冒号 :

我用过
pylint disable=no-self-use
应该是什么时候
pylint: disable=no-self-use

好吧,至少从现在开始我将始终拥有最新的(以及为 python3 构建的)pylint :)