How do I disable a Pylint warning?

2019-01-03 21:18发布

I'm trying to disable warning C0321 ("more than one statement on a single line" -- I often put if statements with short single-line results on the same line), in Pylint 0.21.1 (if it matters: astng 0.20.1, common 0.50.3, Python 2.6.6 (r266:84292, Sep 15 2010, 16:22:56)).

I've tried adding disable=C0321 in the Pylint configuration file, but Pylint insists on reporting it anyway. Variations on that line (like disable=0321 or disable=C321) are flagged as errors, so Pylint does recognize the option properly, it's just ignoring it.

Is this a Pylint bug, or am I doing something wrong? Is there any way around this? I'd really like to get rid of some of this noise.

标签: python pylint
9条回答
劳资没心,怎么记你
2楼-- · 2019-01-03 21:47

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].

查看更多
一纸荒年 Trace。
3楼-- · 2019-01-03 21:52

To disable a warning locally in a block, add

# pylint: disable=C0321

to that block.

查看更多
Viruses.
4楼-- · 2019-01-03 21:55

Starting from Pylint v. 0.25.3, you can use the symbolic names for disabling warnings instead of having to remember all those code numbers. E.g.:

# pylint: disable=locally-disabled, multiple-statements, fixme, line-too-long

This style is more instructive than cryptic error codes, and also more practical since newer versions of Pylint only output the symbolic name, not the error code.

The correspondence between symbolic names and codes can be found here.

A disable comment can be inserted on its own line, applying the disable to everything that comes after in the same block. Alternatively, it can be inserted at the end of the line for which it is meant to apply.

If pylint outputs "Locally disabling" messages, you can get rid of them by including the disable locally-disabled first as in the example above.

查看更多
登录 后发表回答