如何在 vs 代码中禁用 pylint 未使用的导入错误消息 [英] How do I disable pylint unused import error messages in vs code

查看:39
本文介绍了如何在 vs 代码中禁用 pylint 未使用的导入错误消息的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何禁止在 vs 代码的问题框中弹出这些错误消息

How do I disable these error messages from popping up in the problems box in vs code

推荐答案

正如其他人所说,您可以提供一个 disable 参数来禁用特定消息.我想详细说明一下.

As others have said, you can provide a disable argument to disable a specific message. I wanted to elaborate on that.

  1. 这里是禁用多条消息和提供多个参数的语法,我在谷歌上搜索它并没有立即明显:

  1. Here is the syntax for disabling multiple messages and for providing multiple arguments, which was not immediately obvious to me from googling it:

"python.linting.pylintArgs": [
    "--max-line-length=80",
    "--disable=W0142,W0403,W0613,W0232,R0903,R0913,C0103,R0914,C0304,F0401,W0402,E1101,W0614,C0111,C0301"
]

  • 您说过,一旦您禁用该消息,您就会看到更多错误.根据 文档:

    Visual Studio 代码中的 Python 默认配置为使用一组对最大数量的 Python 友好的 linting 规则开发人员:

    Python in Visual Studio code is configured by default to use a set of linting rules that are friendly to the largest number of Python developers:

    • 启用所有错误 (E) 和致命 (F) 消息.
    • 禁用所有约定 (C) 和重构 (R) 消息.
    • 禁用所有警告 (W) 消息,但以下消息除外:
      • 无法访问 (W0101):无法访问的代码
      • duplicate-key (W0109):字典中的重复键 %r
      • 不必要的分号 (W0301):不必要的分号
      • global-variable-not-assigned (W0602):对 %r 使用 global 但未完成分配
      • 未使用的变量 (W0612):未使用的变量 %r
      • 二进制操作异常 (W0711):要捕获的异常是二进制%s"操作的结果
      • 错误格式字符串 (W1302):格式字符串无效
      • anomalous-backslash-in-string (W1401):字符串中的异常反斜杠
      • bad-open-mode (W1501):%s"不是有效的打开模式

      这些规则通过传递给 Pylint 的以下默认参数应用:

      These rules are applied through the following default arguments passed to Pylint:

      --disable=all
      --enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode
      

      这些参数在任何时候被传递python.linting.pylintUseMinimalCheckers 设置为 true(默认值).如果您在 pylintArgs 中指定一个值或使用 Pylint 配置文件(见下一节),然后 pylintUseMinimalCheckers 是隐式设置为 false.

      These arguments are passed whenever the python.linting.pylintUseMinimalCheckers is set to true (the default). If you specify a value in pylintArgs or use a Pylint configuration file (see the next section), then pylintUseMinimalCheckers is implicitly set to false.

      换句话说,PyLint 在 VS Code 中的默认情况下应该是相当宽松的,只显示错误消息和一些精心挑选的警告.但是当您手动将 pylintArgs 设置为某些内容时,pylintUseMinimalCheckers 将被忽略,从而打开所有消息的闸门.这可能就是为什么禁用一条消息会导致显示更多消息的原因.再说一次,我不确定您为什么首先看到未使用的导入消息,因为根据文档,默认情况下它应该被抑制.

      In other words, PyLint is supposedly pretty lax by default in VS Code, only showing you messages for errors and a few hand-picked warnings. But when you manually set pylintArgs to something, pylintUseMinimalCheckers is ignored, opening the floodgates to all messages. That might be why disabling one message resulted in way more messages being shown. Then again, I'm not sure why you were seeing unused-import messages in the first place since it should have been suppressed by default according to the documentation.

      实际上,这目前不起作用: python.linting.pylintUseMinimalCheckers": true(对我来说,在这个特定的时刻,但希望它对你很好,未来的读者).为了获得同样的效果,我必须手动将 pylintArgs 设置为它应该自动设置的值:

      Actually, this currently doesn't work: python.linting.pylintUseMinimalCheckers": true (for me, at this particular moment in time, but hopefully it works fine for you, future reader). To get the same effect, I had to manually set pylintArgs to the value it was supposed to be setting automatically:

      "python.linting.pylintArgs": [
          "--disable=all",
          "--enable=F,E,unreachable,duplicate-key,unnecessary-semicolon,global-variable-not-assigned,unused-variable,binary-op-exception,bad-format-string,anomalous-backslash-in-string,bad-open-mode"
      ]
      

    • 奖励:这是我使用的禁用消息列表的解释,如上面第 1 点所示.它主要取自 此处:

    • BONUS: Here's an explanation of the list of disabled messages I use, as shown above in point 1. It's mostly taken from here:

      # Disabled messages
      #    Pointless
      #       W0142 = *args and **kwargs support
      #       W0403 = Relative imports
      #       W0613 = Unused argument
      #       W0232 = Class has no __init__ method
      #       R0903 = Too few public methods
      #       R0913 = Too many arguments
      #       C0103 = Invalid name
      #       R0914 = Too many local variables
      #       C0304 = Final newline missing
      #
      #    PyLint's module importation is unreliable
      #       F0401 = Unable to import module
      #       W0402 = Uses of a deprecated module
      #       E1101 = Module x has no y member
      #
      #    Already an error when wildcard imports are used
      #       W0614 = Unused import from wildcard
      #
      #    Stricter messages that can be disabled until everything else has been fixed
      #       C0111 = Missing docstring
      #       C0301 = Line too long
      

    • 这篇关于如何在 vs 代码中禁用 pylint 未使用的导入错误消息的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆