Python Pylint 只显示警告和错误

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/31907762/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 10:43:36  来源:igfitidea点击:

Pylint to show only warnings and errors

pythonpylint

提问by joetde

I would like to use pylint to check my code but I am only interested in error and warning levels. Is there a way to do that in command line or in pylintrc?

我想使用 pylint 检查我的代码,但我只对错误和警告级别感兴趣。有没有办法在命令行或 pylintrc 中做到这一点?

I am not interested in filtering given issues (like listing all messages in MESSAGE CONTROL), I just want pylint to ignore allconvention and refactor messages.

我对过滤给定的问题不感兴趣(比如在 MESSAGE CONTROL 中列出所有消息),我只希望 pylint 忽略所有约定和重构消息。

Note: I don't think that's a duplicate of Using Pylint to display error and warnings

注意:我不认为这是使用 Pylint 显示错误和警告的重复

采纳答案by Steven Kryskalla

Use the -d/ --disableoption to turn off the "C" and "R" message classes (convention and refactor):

使用-d/--disable选项关闭“C”和“R”消息类(约定和重构):

-d <msg ids>, --disable=<msg ids>
                    Disable the message, report, category or checker with
                    the given id(s). You can either give multiple
                    identifiers separated by comma (,) or put this option
                    multiple times (only on the command line, not in the
                    configuration file where it should appear only
                    once).You can also use "--disable=all" to disable
                    everything first and then reenable specific checks.
                    For example, if you want to run only the similarities
                    checker, you can use "--disable=all
                    --enable=similarities". If you want to run only the
                    classes checker, but have no Warning level messages
                    displayed, use"--disable=all --enable=classes
                    --disable=W"

Without the disableoption (6 convention, 1 refactor, 2 warning, 1 error):

没有disable选项(6 个约定,1 个重构,2 个警告,1 个错误):

$ pylint x.py
C:  1, 0: Missing module docstring (missing-docstring)
C:  3, 0: Missing function docstring (missing-docstring)
R:  3, 0: Too many statements (775/50) (too-many-statements)
W:780,15: Redefining name 'path' from outer scope (line 796) (redefined-outer-name)
C:780, 0: Invalid function name "getSection" (invalid-name)
C:780, 0: Empty function docstring (empty-docstring)
C:782,23: Invalid variable name "inPath" (invalid-name)
W:785, 4: Statement seems to have no effect (pointless-statement)
E:785, 4: Undefined variable 'something' (undefined-variable)
C:796, 4: Invalid constant name "path" (invalid-name)

After using the disableoption (0 convention, 0 refactor, 2 warning, 1 error):

使用disable选项后(0 约定,0 重构,2 警告,1 错误):

$ pylint --disable=R,C x.py
W:780,15: Redefining name 'path' from outer scope (line 796) (redefined-outer-name)
W:785, 4: Statement seems to have no effect (pointless-statement)
E:785, 4: Undefined variable 'something' (undefined-variable)

To set this option in pylintrc:

要在 中设置此选项pylintrc

disable=R,C

回答by themadmax

> python -m pylint --errors-only script_to_validate.py
No config file found, using default configuration
************* Module script_to_validate
E:  7,10: Module 'cv2' has no 'imread' member (no-member)
E:  8,15: Module 'cv2' has no 'threshold' member (no-member)

My settings is Python2.7.6 32 bit & pylint 1.6.4

我的设置是 Python2.7.6 32 位 & pylint 1.6.4