Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I disable pylint unused import error messages in vs code

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

error messages

like image 922
Turtle Gurgle Avatar asked Aug 31 '18 23:08

Turtle Gurgle


People also ask

How do I disable VSCode Pylint warnings?

Go to the menu File -> Preferences -> Settings (Or open directly with Command + , or Ctrl + , ). Then in the search box at the top of the window, search for pylint Args . Click on the button Add item and add the line --disable=W .

How do I fix Pylint import error in VSCode?

db' pylint(import-error) showing up. This is because VS Code is not running the Virtual Environment of the app. To fix it, run cmd-shift-p (or click View -> Command Palette and run the command Python: Select Interpreter. VS Code will show you a list of Python interpreters found.

How do you make a Pylint ignore an error?

you can ignore it by adding a comment in the format # pylint: disable=[problem-code] at the end of the line where [problem-code] is the value inside pylint(...) in the pylint message – for example, abstract-class-instantiated for the problem report listed above.

How do you remove Pylint?

If you just want to disable pylint then the updated VSCode makes it much more easier. Just hit CTRL + SHIFT + P > Select linter > Disabled Linter. Hope this helps future readers.


1 Answers

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

  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" ] 
  2. You stated that you started seeing way more errors once you disabled that one message. That actually might make sense according to the documentation:

    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:

    • Enable all Error (E) and Fatal (F) messages.
    • Disable all Convention (C) and Refactor (R) messages.
    • Disable all Warning (W) messages except the following:
      • unreachable (W0101): Unreachable code
      • duplicate-key (W0109): Duplicate key %r in dictionary
      • unnecessary-semicolon (W0301): Unnecessary semicolon
      • global-variable-not-assigned (W0602): Using global for %r but no assignment is done
      • unused-variable (W0612): Unused variable %r
      • binary-op-exception (W0711): Exception to catch is the result of a binary "%s" operation
      • bad-format-string (W1302): Invalid format string
      • anomalous-backslash-in-string (W1401): Anomalous backslash in string
      • bad-open-mode (W1501): "%s" is not a valid mode for open

    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 

    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.

    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.

  3. 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" ] 
  4. 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 
like image 136
MarredCheese Avatar answered Sep 20 '22 01:09

MarredCheese