8

是否可以在 python 源代码本身中禁用某些 pylint 错误/警告?

4

3 回答 3

13
def foo():
    print "000000000000000000000000000000000000000000000000000000000000000000000000000"
print "111111111111111111111111111111111111111111111111111111111111111111111111111"

pylint 输出:

C:  2: Line too long (87/80)
C:  3: Line too long (83/80)
C:  1: Missing docstring
C:  1:foo: Black listed name "foo"
C:  1:foo: Missing docstring

添加注释“# pylint: disable=CODE”,“行太长”消息的代码 - C0301:

def foo():
    # pylint: disable=C0301
    print "000000000000000000000000000000000000000000000000000000000000000000000000000"
print "111111111111111111111111111111111111111111111111111111111111111111111111111"

pylint 输出:

I:  2: Locally disabling C0301
C:  4: Line too long (83/80)
C:  1: Missing docstring
C:  1:foo: Black listed name "foo"
C:  1:foo: Missing docstring
于 2012-09-24T21:30:23.350 回答
8

@kalgasnik 提到的 #pylint: disable 语法是正确的。您可以在Pylint 常见问题解答中找到更多相关信息(您的问题是meth2

于 2012-09-25T07:02:12.060 回答
5

在 Eclipse IDE 中,使用 pydev,您可以在代码行之后添加注释,格式为# IGNORE:_ID_. 我不知道这是否也适用于其他程序。例如:

import something  # IGNORE:W0611
于 2012-09-24T21:22:27.743 回答