Search code examples
pythonpylintpep8flake8

Why do pylint and flake8 raise different messages?


Suppose I have this method:

def test_method():
    #comment here
    my_variable=1
    print(my_variable)
    raise Exception('Exception message')

When I use pylint, these messages were raised:

test.py:1:0: C0116: Missing function or method docstring (missing-function-docstring)
test.py:5:4: W0719: Raising too general exception: Exception (broad-exception-raised)

And with flake8, other messages appeared:

test.py:2:5: E265 block comment should start with '# '
test.py:3:16: E225 missing whitespace around operator

Why do they raise different messages? I expect one of them should raise all above messages, since they are all PEP8 standards.

Did I miss some configuration? Or do I have to use both pylint and flake8 in a project?


Solution

  • PyLint does not generally have the goal of checking PEP8. It does have some overlap, but because it tends to be rather expensive to run wasting time on basic PEP8 checks which other checkers can do much more easily and cheaply is not something the project is usually interested in. Specifically pylint tends towards cross-file analysis, extensibility, and more subjective prescriptive assertions.

    If you look for pep8 stuff on the tracker, the pylint project generally recommends a separate checker for those properties e.g. pycodestyle.

    So yes, you should use both pylint and an other checker (pep8 or pycodestyle) if you want to check for both pylint's stuff and pep8 properties.