Pylint disables all warnings for a file

We use pylint in our build system. We have a python package inside our code base that has throwaway code, and I would like to temporarily disable all warnings for the module so that I can stop listening to other developers with these extra messages. Is there an easy way to pylint: disable all warnings for a module?

+43
python pylint
Apr 19 2018-12-12T00:
source share
5 answers

From the PyLint FAQ

With Pylint <0.25, add

 # pylint: disable-all 

at the beginning of the module.

Pylint 0.26.1 and up renamed this directive to

 # pylint: skip-file 

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

To facilitate the search for which modules are ignored, information level message I0013 is displayed. In recent versions of Pylint, if you use the old syntax, an additional message I0014 is issued.

+52
Apr 20 2018-12-12T00:
source share

PyLint has five β€œcategories” for posts (which I know of).

These categories were very obvious, but Pylint's numbered posts are now replaced with names. For example, C0302 now too-many-lines . But "C" tells us that too-many-lines is a conference message. This is confusing because messages under the Convention often appear as a warning, since many systems (such as Syntastic ) seem to classify everything as either a warning or an error. However, the PyLint report still destroys all of these categories, so it is definitely definitely supported.

Your question specifically mentions warnings, and all PyLint Warning message names begin with "W".

It was hard for me to track this, but this answer ultimately led me to the answer. PyLint still supports disabling entire categories of messages. So, to disable all warnings, you must:

 disable=W 

This can be used on the command line:

 $ pylint --disable=W myfile.py 

Or you can put it in your pylintrc file:

 [MESSAGES CONTROL] disable=W 

Note. Perhaps you already have the disable option in your rc file, in which case you should add "W" to this list.

Or you can put it in your code in your code, where it will work for the area in which it is placed:

 # pylint: disable=W 

To disable it for the entire file, it is best to put it at the very top of the file. However, even at the very top corner of the file, I found that I was still receiving the warning message trailing-newlines (technically this is a conditional warning, but I get to that).

In my case, I had a library written by someone a long time ago. It worked well, so there was no need to worry about the modern Python convention, etc. All I really worried about were bugs that would probably break my code.

My solution was to disable all the Warning, Convention, and Refactoring messages for this single file, only putting the following PyLint command on the first line:

 # pylint: disable=W,C,R 

Besides the above post for trailing lines, this did exactly what I needed.

+6
Apr 20 '17 at 4:37 on
source share

Another option is to use the --ignore command-line --ignore to skip the analysis for some files.

+5
Apr 23 '12 at 7:11
source share

Yes, you can specify # pylint: skip-file , but it is incorrect to use all warnings for the file. The leak code should not exist in the branch that pylint parses.

If you want to disable only specific warnings, you can do this by adding a comment, for example # pylint: disable=message-name , to disable the specified message for the rest of the file, or at least up to # pylint: enable=message-name .

Example:

 # pylint: disable=no-member class C123(object): def __init__(self): self.foo_x = self.bar_x # pylint: enable=no-member class C456(object): def __init__(self): self.foo_x = self.bar_x 
+1
Jan 26 '17 at 20:24
source share

My use case is to run pylint *.py to process all the files in a directory, except that I want to skip one specific file.

Adding #pylint: skip-file caused a pylint error with I: 8, 0: Ignoring entire file (file-ignored) . Adding #pylint: disable=file-ignored does not fix this. Presumably this is a global error, not a file-specific one.

The solution was to include --disable=file-ignored in the pylint command options. It took too long to figure it out; There should be no file-ignored error when you explicitly ignore the file.

0
Jun 03 '17 at 2:13 on
source share



All Articles