How to Disable a Pylint Warning

How do I disable a Pylint warning?

pylint --generate-rcfile shows it like this:

[MESSAGES CONTROL]

# Enable the message, report, category or checker with the given id(s). You can
# either give multiple identifier separated by comma (,) or put this option
# multiple time.
#enable=

# Disable the message, report, category or checker with the given id(s). You
# can either give multiple identifier separated by comma (,) or put this option
# multiple time (only on the command line, not in the configuration file where
# it should appear only once).
#disable=

So it looks like your ~/.pylintrc should have the disable= line/s in it inside a section [MESSAGES CONTROL].

Is it possible to ignore one single specific line with Pylint?

Pylint message control is documented in the Pylint manual:

Is it possible to locally disable a particular message?

Yes, this feature has been added in Pylint 0.11. This may be done by adding
# pylint: disable=some-message,another-one
at the desired block level or at the end of the desired line of code.

You can use the message code or the symbolic names.

For example,

def test():
# Disable all the no-member violations in this function
# pylint: disable=no-member
...
# pylint: enable=no-member

apply to a specific line only:

global VAR  # pylint: disable=global-statement

or for less verbosity, disable the ONLY following line (pylint 2.10+):

# pylint: disable-next=global-statement
global VAR

Pylint's manual also has further examples.

There is a wiki that documents all Pylint messages and their codes.

How to disable pylint warnings and messages on Visual Studio Code?

Fully disable the linting

Here is a link that explain how to do it : Disable Linting on VsCode.

To do so, type Command + Shift + P (or Ctrl + Shift + P on PC) in VsCode. This will open a command prompt at the top of the window. Then type the command Python: Enable Linting, and select off.

Another option is to choose no linter. To do so, open the command prompt with Command + Shift + P (or Ctrl + Shift + P on PC), type Python: Select Linter, and choose the option Disable Linting.


Disable warnings, but keep errors :

If you want to keep the errors, but disable only the warnings, you can also configure pylint directly from VsCode. 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.

Sample Image

Disable all Pylint warnings for a file

From the Pylint FAQ:

With Pylint < 0.25, add

# pylint: disable-all

at the beginning of the module.

Pylint 0.26.1 and up have renamed that directive to

# pylint: skip-file

(but the first version will be kept for backward compatibility).

In order to ease finding which modules are ignored a information-level message I0013 is emitted. With recent versions of Pylint, if you use the old syntax, an additional I0014 message is emitted.

How do I disable a Pylint specific error message globally?

In order for pylint to automatically pick up your rc file, it should be located at ~/.pylintrc. Otherwise you would need to pass the rc file as an argument on every invocation of pylint.



Related Topics



Leave a reply



Submit