38

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

error messages

Paul Rooney
  • 20,879
  • 9
  • 40
  • 61
Turtle Gurgle
  • 391
  • 1
  • 3
  • 4
  • 5
    Don't wildcard import, `from x import *` it can lead to hard to detect issues. Better just to `import x` and then use `x.Name`. If `x` is very large then shorten it with `as` e.g. `import numpy as np`. If there are just a limited number of objects then import them explicitly, e.g. `from x import A, B, C` – AChampion Aug 31 '18 at 23:58
  • Perhaps, instead of disabling the import errors, you may want to fix them by telling `pylint` where to find your modules. See [pylint-unable-to-import-error-how-to-set-pythonpath](https://stackoverflow.com/questions/1899436/pylint-unable-to-import-error-how-to-set-pythonpath/3065082#3065082) – Ricardo May 31 '22 at 17:45

8 Answers8

60

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
    
MarredCheese
  • 17,541
  • 8
  • 92
  • 91
  • 2
    I think this should be the accepted answer. Not only do you give the answer to disable warning and error messages, you give a reason why they might be seeing the 500+ messages after disabling them. – ztindall Apr 04 '19 at 19:08
  • 4
    A full list of codes is available here: http://pylint-messages.wikidot.com/all-codes. – Gino Mempin Jul 14 '19 at 04:27
  • Try putting `python.linting.pylintUseMinimalCheckers": true` **after** the custom pylint settings in your json – Michael May 06 '20 at 09:44
  • 1
    @nonein The file is "settings.json." To open it, go to File > Preferences > Settings and click the button at the top right that says "Open Settings (JSON)" when you hover over it. – MarredCheese Sep 14 '20 at 16:50
  • 1
    A more complete list of codes is avaible in official docs: https://docs.pylint.org/en/latest/technical_reference/features.html – ambigus9 Dec 15 '21 at 01:33
  • 2
    The answer is much wider than the question, very useful. Meanwhile in the latest version of VS Code you should not open JSON file, you just need to find 'Pylint Args' in the Settings and add items, line by line. – Kostiantyn Ivashchenko Jul 19 '22 at 18:47
10
"python.linting.pylintArgs": [
    "--disable=C0111"
],

You can also disable by message type, e.g., --disable=W.

A good reference is www.pylintcode.info, with a list of message ids and message types.

MarredCheese
  • 17,541
  • 8
  • 92
  • 91
joepitz1
  • 194
  • 2
  • 12
  • 1
    it doeesn't seem to work. I see now 500+ warnings that I didn't see before. I think it disables all other arguments. note that pylinArgs was empty before. – maugch Dec 12 '18 at 11:06
  • 2
    The link is dead. Here's an alternative: http://pylint-messages.wikidot.com/all-codes – Gino Mempin Jul 14 '19 at 04:20
6

Adding below to lines at the top of the file will remove the error...And make sure is the lines duplicated inside the program if yes remove it.

 # pylint: disable=unused-wildcard-import, method-hidden
 # pylint: enable=too-many-lines

Reference: https://pylint.readthedocs.io/en/latest/faq.html#is-it-possible-to-locally-disable-a-particular-message

Kowsalya R
  • 280
  • 6
  • 10
3

In your VS Code Settings (CTRL+COMMA)

"python.linting.pylintArgs": [
    "--disable=W0614"
],

For more ideas: https://code.visualstudio.com/docs/python/linting#_commandline-arguments-and-configuration-files

Patrick
  • 2,044
  • 1
  • 25
  • 44
  • 3
    it doeesn't seem to work anymore. I see now 500+ warnings that I didn't see before. I think it disables all other arguments. note that pylinArgs was empty before. – maugch Dec 12 '18 at 11:06
  • The link is broken and the answer duplicates the https://stackoverflow.com/a/52129121/7869636 – Ashark Jun 11 '22 at 20:51
1

For the simple test.py, I did not modify setting but only apply to that file I used # pylint: disable=W0614 Put this line on top of the file then pylint automatically recognized it.

This eliminated 100 unused import warnings

You can keep disabling like this

# pylint: disable=missing-module-docstring
# pylint: disable=missing-class-docstring
# pylint: disable=missing-function-docstring
# pylint: disable=wildcard-import
# pylint: disable=W0614
Jae Mun Choi
  • 129
  • 1
  • 4
1

Add to settings.json in your .vscode folder.:

{
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.linting.pylintArgs": [
        "--disable=C0116,C0301,C0303,C0325,W0311,W1202,W1201,W1203,W1309,W0702,C0103,C0415"
    ]
}

Where --disable=XXXX can be found in official docs: https://docs.pylint.org/en/latest/technical_reference/features.html

ambigus9
  • 1,417
  • 3
  • 19
  • 37
1

As an alternative solution, instead of disabling the import errors messages, you may want to fix them by telling pylint where to find your modules*.

So, you would add to settings.json in your .vscode folder:

{
    "python.linting.pylintEnabled": true,
    "python.linting.enabled": true,
    "python.linting.pylintArgs": [
        "--init-hook",
        "import sys; sys.path.append('./mysite')",
        "--disable=XYZ"
    ]
}

Where

  1. ./mysite should be the path to your root directory (if you're using Django, this is the container for your project)
  2. XYZ is a csv list of rules you actually want to disable; if you really want, you can disable import-error by adding E0401 here

* See more at pylint-unable-to-import-error-how-to-set-pythonpath

Ricardo
  • 3,696
  • 5
  • 36
  • 50
0

I use pylint

Ctrl+P: Python Select Linter > select pylint

一. vscode says those warning type

  • Unused PrimaryKeyConstraint imported from sqlalchemypylint(unused-import)
  • Imports from package sqlalchemy are not groupedpylint(ungrouped-imports)
  • Import "import logging" should be placed at the top of the modulepylint(wrong-import-position)
  • standard import "import logging" should be placed before "from sqlalchemy import Column, Integer, String"pylint(wrong-import-order)
  • Line too long (141/100)pylint(line-too-long)
  • ...

二. ignore those warning type in setting

Ctrl+P: WorkSpace Setting JSON

{
    "python.linting.pylintArgs": [
        "--disable=wrong-import-order,wrong-import-position,unused-import,ungrouped-imports,line-too-long"
    ],
}

OR use setting ui

Ctrl+P: WorkSpace Setting

search python.linting.pylintArgs

Add Item OR edit item existed.

yurenchen
  • 1,897
  • 19
  • 17