Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

python: pycodestyle (ex pep8) vs pylint strictness

I have a python project that I want to check against PEP8 conformance.

My setyp.cfg is the following:

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

After some cleaning up, my pycodestyle check is now yileding no errors nor warnings (the ones ignored aside of course)

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

However, running pylint against my project yields a ton of errors:

(some of them follow just for demonstration purposes)

************* 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)

How can it be that these 2 tools yield so deviating results?

like image 588
pkaramol Avatar asked Jul 29 '19 14:07

pkaramol


People also ask

What is the difference between Pylint and pycodestyle?

In short the answer is that pycodestyle is "a subset" of pylint. Let me quote a little something from essential python tools: Pycodestyle (Formerly PEP8) is the official linter tool to check the python code against the style conventions of PEP8 python.

What is pycodestyle and how to install it?

A blank line between each group of imports. Pycodestyle (Formerly PEP8) is the official linter tool to check the python code against the style conventions of PEP8 python. To install it: pip install pycodestyle. Let us take a small example script to test pycodestyle

How do I install Pylint on VS Code?

To install pylint run the following code; $ code . You should see something similar to the above result. Next we select our Python Interpreter Just select the python3/2 with virtualenv enabled. This will ensure that Vs code picks up tools we installed in virtual env. Next we finally activate linting on Vs code.

What is the use of Pylint in Python?

pylint ¶. Pylint is a python linter which checks the source code and also acts as a bug and quality checker. It has more verification checks and options than just PEP8 (Python style guide). This is the most commonly used tool for linting in python.


1 Answers

I just stumbled over this question comparing pycodestyle and pylint myself.

In short the answer is that pycodestyle is "a subset" of pylint. Let me quote a little something from essential python tools:

  • Pycodestyle (Formerly PEP8) is the official linter tool to check the python code against the style conventions of PEP8 python.
  • Pylint is a python linter which checks the source code and also acts as a bug and quality checker. It has more verification checks and options than just PEP8(Python style guide).
    • This is the most commonly used tool for linting in python.
    • It includes the following features:
      • Checking the length of each line
      • Checking if variable names are well-formed according to the project’s coding standard
      • Checking if declared interfaces are truly implemented.
      • ...
like image 163
thorsten Avatar answered Sep 27 '22 21:09

thorsten