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


Asked By – The Unfun Cat

I have the following line in my header:

import config.logging_settings

This actually changes my Python logging settings, but Pylint thinks it is an unused import. I do not want to remove unused-import warnings in general, so is it possible to just ignore this one specific line?

I wouldn’t mind having a .pylintrc for this project, so answers changing a configuration file will be accepted.

Otherwise, something like this will also be appreciated:

import config.logging_settings # pylint: disable-this-line-in-some-way

Now we will see solution for issue: 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
global VAR # pylint: disable=global-statement

The manual also has further examples.

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

This question is answered By – jomo

This answer is collected from stackoverflow and reviewed by FixPython community admins, is licensed under cc by-sa 2.5 , cc by-sa 3.0 and cc by-sa 4.0