我试图在Pylint 0.21.1中禁用警告C0321(“单行中有多个语句”——我经常将具有短单行结果的if语句放在同一行上)(如果有问题:astng 0.20.1, common 0.50.3,和Python 2.6.6 (r266:84292, 2010年9月15日,16:22:56))。

我尝试在Pylint配置文件中添加disable=C0321,但Pylint坚持报告它。这一行的变体(如disable=0321或disable=C321)被标记为错误,因此Pylint能够正确地识别该选项。它只是忽略它。

这是一个Pylint错误,还是我做错了什么?有办法解决这个问题吗?

我真的很想摆脱这些噪音。


当前回答

编辑“C:\Users\Your User\AppData\Roaming\Code\User\settings.json” 并添加'python.linting。pylintArgs'和它的行在最后如下所示:

{
    "team.showWelcomeMessage": false,
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "git.enableSmartCommit": true,
    "powershell.codeFormatting.useCorrectCasing": true,
    "files.autoSave": "onWindowChange",
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django",
        "--errors-only"
    ],
}

其他回答

若要在块中禁用本地警告,请添加

# pylint: disable=C0321

到那个街区。

编辑“C:\Users\Your User\AppData\Roaming\Code\User\settings.json” 并添加'python.linting。pylintArgs'和它的行在最后如下所示:

{
    "team.showWelcomeMessage": false,
    "python.dataScience.sendSelectionToInteractiveWindow": true,
    "git.enableSmartCommit": true,
    "powershell.codeFormatting.useCorrectCasing": true,
    "files.autoSave": "onWindowChange",
    "python.linting.pylintArgs": [
        "--load-plugins=pylint_django",
        "--errors-only"
    ],
}

根据Pylint文档,最简单的是使用这个图表:

C约定相关的检查 R重构相关的检查 W各种警告 E错误,用于代码中可能的错误 F致命,如果发生错误导致Pylint无法进行进一步处理。

所以你可以用:

pylint -j 0 --disable=I,E,R,W,C,F YOUR_FILES_LOC

还可以使用以下命令:

pylint --disable=C0321  test.py

我的Pylint版本是0.25.1。

你只需要添加一行来禁用你想禁用的东西。

例如,

#pylint: disable = line-too-long, too-many-lines, no-name-in-module, import-error, multiple-imports, pointless-string-statement, wrong-import-order

将此添加到模块的最开始。