pycodestyle(以前的pep8)与pylint的严格程度对比

10

我有一个涉及Python的项目,我想要对其进行PEP8规范性检查。

我的setyp.cfg文件如下:

[pycodestyle]
count = True
ignore = E266, W504
max-line-length = 80
statistics = True
exclude = .venv,./build%

经过一些清理,我的pycodestyle检查现在没有任何错误或警告(当然忽略了被忽略的部分)

~/Workspace/my-app  master ✔                                                                                                                        2h36m
➢  pycodestyle .
(.venv)
~/Workspace/my-app  master ✔

然而,对我的项目运行pylint会产生大量错误:

(以下仅为演示部分错误)

************* Module somemodule.commands
src/somemodule/commands.py:98:0: C0330: Wrong continued indentation (add 16 spaces).
                            format(gcp_project)))
                            ^               | (bad-continuation)
src/somemodule/commands.py:1:0: C0111: Missing module docstring (missing-docstring)
src/somemodule/commands.py:21:-1: W0105: String statement has no effect (pointless-string-statement)
src/somemodule/commands.py:29:4: C0103: Variable name "p" doesn't conform to snake_case naming style (invalid-name)
src/somemodule/commands.py:45:4: C0103: Variable name "p" doesn't conform to snake_case naming style (invalid-name)
src/somemodule/commands.py:41:16: W0613: Unused argument 'g_project' (unused-argument)
src/somemodule/commands.py:58:0: C0111: Missing function docstring (missing-docstring)
src/somemodule/commands.py:59:4: C0103: Variable name "p" doesn't conform to snake_case naming style (invalid-name)
src/somemodule/commands.py:100:4: R1705: Unnecessary "else" after "return" (no-else-return)
src/somemodule/commands.py:102:8: C0103: Variable name "p2" doesn't conform to snake_case naming style (invalid-name)
src/somemodule/commands.py:123:4: C0103: Variable name "p" doesn't conform to snake_case naming style (invalid-name)
src/somemodule/commands.py:139:0: C0111: Missing function docstring (missing-docstring)
src/somemodule/commands.py:2:0: C0411: standard import "import os" should be placed before "import click" (wrong-import-order)
src/somemodule/commands.py:3:0: C0411: standard import "import sys" should be placed before "import click" (wrong-import-order)
src/somemodule/commands.py:5:0: C0411: standard import "from subprocess import Popen, PIPE" should be placed before "import click" (wrong-import-order)

这两个工具为什么会产生如此不同的结果呢?
1个回答

20

我刚刚偶然看到这个比较pycodestylepylint的问题。

简而言之,答案是pycodestylepylint的“子集”。让我引用一些来自essential python tools的内容:

  • Pycodestyle(曾经是 PEP8)是官方的代码检查工具,用于检查 Python 代码是否符合 PEP8 的风格约定。
  • Pylint是一个 Python 代码检查器,它可以检查源代码并充当错误和质量检查器。它具有比仅仅遵循 PEP8(Python 样式指南)更多的验证检查和选项。
    • 这是 Python 中最常用的检查工具。
    • 它包括以下功能:
      • 检查每行的长度
      • 检查变量名是否按照项目的编码标准格式编写
      • 检查声明的接口是否真正实现。
      • ...

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接