Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

python

pylint

People also ask

How do you ignore specific Pylint errors?

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.

How do I know if a Pylint is ignoring a file?

The solution was to include --disable=file-ignored in the Pylint command options.

Does Pylint have no member?

If you are getting the dreaded no-member error, there is a possibility that either: pylint found a bug in your code. You're launching pylint without the dependencies installed in its environment. pylint would need to lint a C extension module and is refraining to do so.

How do I ignore a folder in Pylint?

You can not give a path, but only the "basename" of the directory. E.g., use --ignore=lib instead of --ignore-=appengine-toolkit/gaetk/lib . The problem is you will ignore all directories named lib .


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
    ...
global VAR # pylint: disable=global-statement

The manual also has further examples.

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


import config.logging_settings # pylint: disable=W0611

That was simple and is specific for that line.

You can and should use the more readable form:

import config.logging_settings # pylint: disable=unused-import

I believe you're looking for...

import config.logging_settings  # @UnusedImport

Note the double space before the comment to avoid hitting other formatting warnings.

Also, depending on your IDE (if you're using one), there's probably an option to add the correct ignore rule (e.g., in Eclipse, pressing Ctrl + 1, while the cursor is over the warning, will auto-suggest @UnusedImport).


Checkout the files in https://github.com/PyCQA/pylint/tree/master/pylint/checkers. I haven't found a better way to obtain the error name from a message than either Ctrl + F-ing those files or using the GitHub search feature:

If the message is "No name ... in module ...", use the search:

No name %r in module %r repo:PyCQA/pylint/tree/master path:/pylint/checkers

Or, to get fewer results:

"No name %r in module %r" repo:PyCQA/pylint/tree/master path:/pylint/checkers

GitHub will show you:

"E0611": (
    "No name %r in module %r",
    "no-name-in-module",
    "Used when a name cannot be found in a module.",

You can then do:

from collections import Sequence # pylint: disable=no-name-in-module

In addition to the accepted answer:

You can re-enable the error checking adding pylint: enable:SPECIFIC_ERROR

For example, I have this in my code:

import time
import datetime
import os
import sys
# pylint: disable=import-error
import serial
# pylint: enable=import-error

This way you can ignore a single error on a single line without having to disable checking that error in the whole file