Is it possible to ignore one single specific line with Pylint?
Pylint message control is documented in the Pylint manual:
Yes, this feature has been added in Pylint 0.11. This may be done by addingIs it possible to locally disable a particular message?
# 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.
Is it possible to ignore one single specific line with pylint, without changes to the source code?
I don't think it is possible to ignore a specific line without changing the source code. However, it is certainly possible to ignore warning types in the .pylintrc
or at the top of file.
I'd go with the approach of creating a .pylintrc to suit your needs. For example, if you want to completely ignore W0612: unused-variable
then you can create a .pylintrc file and add message names to disable as noted in pytest docs.
.pylintrc
disable=unused-variable,
...,
Alternatively, you can disable messages on a case by case basis at the top of the file, and just tell your students to ignore it: Top of file
# pylint: disable=unused-variable, wildcard-import, method-hidden
# pylint: enable=too-many-lines
VS Code: Tell pylint to ignore the next line?
You can use # pylint: disable=fixme, line-too-long
. See this StackOverflow answer.
How to suppress a warning in one line for pylint and Flake8 at the same time
both of these combinations work for me:
import os # noqa: F401 # pylint:disable=unused-import
import sys # pylint:disable=unused-import # noqa: F401
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]
. How to ignore a specific Pylint message in Atom Editor?
You could always disable specific messages using this template in the first line (top line) of your code:
#pylint: disable=<error_name/number>,..,..
In your example you could use:
#pylint: disable=W0311
Pylint recognizes this format and disables this message, so when you run Pylint it should not check for this error.
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
Most Efficient Way to Reverse a Numpy Array
Extracting Days from a Numpy.Timedelta64 Value
How to Troubleshoot Python "Could Not Find Platform Independent Libraries <Prefix>"
Python and Operator on Two Boolean Lists - How
How to Calculate the Inverse of the Normal Cumulative Distribution Function in Python
In Python, Why Is List[] Automatically Global
Weighted Standard Deviation in Numpy
How to Test a Function with Input Call
Row-Wise Average for a Subset of Columns with Missing Values
Loading JSONl File as JSON Objects
Apt Command Line Interface-Like Yes/No Input
Numpy 1.21.2 May Not Yet Support Python 3.10
Python: Can't Pickle Type X, Attribute Lookup Failed
Start a Flask Application in Separate Thread
Joining Pairs of Elements of a List
Powersets in Python Using Itertools
Memoization Library for Python 2.7
Brew Installation of Python 3.6.1: [Ssl: Certificate_Verify_Failed] Certificate Verify Failed