gpt4 book ai didi

python: pycodestyle (ex pep8) vs pylint 严格性

转载 作者:行者123 更新时间:2023-12-03 20:15:09 25 4
gpt4 key购买 nike

我有一个 python我要检查的项目 PEP8一致性。

我的 setyp.cfg如下:

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

经过一番清理,我的 pycodestyle check 现在没有错误也没有警告(当然忽略的那些)
~/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)

这两种工具怎么会产生如此不同的结果?

最佳答案

我只是偶然发现了这个问题比较 pycodestylepylint我。

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

  • Pycodestyle(以前的 PEP8)是官方的 linter 工具,用于根据 PEP8 python 的样式约定检查 python 代码。
  • Pylint 是一个 python linter,它检查源代码并充当错误和质量检查器。它具有比 PEP8(Python 样式指南)更多的验证检查和选项。
  • 这是python中最常用的linting工具。
  • 它包括以下功能:
  • 检查每行的长度
  • 根据项目的编码标准检查变量名称是否格式正确
  • 检查声明的接口(interface)是否真正实现。
  • ...
  • 关于python: pycodestyle (ex pep8) vs pylint 严格性,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57256056/

    25 4 0
    Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
    广告合作:1813099741@qq.com 6ren.com