I am trying to run Flake8 for my python code however I'm noticing it's not giving me any of the PyDocStyle errors on a simple class with missing docstrings or warning about my class name cars
which should be Cars
according to PEP8 style guide
Example code file (cars.py)
class cars:
def __init__(self, some_value):
self.some_value = some_value
when I run flake8 cars.py
I get the following output:
cars.py:3:37: W292 no newline at end of file
I'm trying to configure Flake8 to run some common style checks but not finding any help in the Flake8 documentation about how to enable PyDocStyle error codes.
For comparison, I ran the same file against Pylint and here is the output
************* Module code.cars
cars.py:3:0: C0304: Final newline missing (missing-final-newline)
cars.py:1:0: C0114: Missing module docstring (missing-module-docstring)
cars.py:1:0: C0103: Class name "cars" doesnt conform to PascalCase naming style (invalid-name)
cars.py:1:0: C0115: Missing class docstring (missing-class-docstring)
cars.py:1:0: R0903: Too few public methods (0/2) (too-few-public-methods)
------------------------------------
Your code has been rated at -6.67/10
I'm using python 3.7.6, flake8 3.7.9 (mccabe: 0.6.1, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.6 on Linux
So what I found out was that by default Flake8 wraps pycodestyle: 2.5.0
by default which from the documentation says:
Among other things, these features are currently not in the scope of the pycodestyle library:
- naming conventions: this kind of feature is supported through plugins. Install flake8 and the pep8-naming extension to use this feature.
- docstring conventions: they are not in the scope of this library; see the pydocstyle project.
- automatic fixing: see the section PEP8 Fixers in the related tools page.
So I installed pep8-naming
, as well as flake8-docstrings
and after running flake8 --version
I got the below which shows it is now using the installed plugins:
3.7.9 (flake8-docstrings: 1.5.0, pydocstyle: 5.0.2, mccabe: 0.6.1, naming: 0.8.2, pycodestyle: 2.5.0, pyflakes: 2.1.1) CPython 3.7.6 on Darwin
I reran my check flake8 cars.py
and I got the below output:
cars.py:1:1: D100 Missing docstring in public module
cars.py:2:1: D101 Missing docstring in public class
cars.py:2:8: N801 class name 'cars' should use CapWords convention
cars.py:3:1: D107 Missing docstring in __init__
At a first impression - after checking out the git repos for flake8
and the additional plugins I had to install I am slightly skeptical on Flake8. The reason being is as at the time of writing Pylint seems to come packaged with the behavior I need as well as being around longer which benefits from stability and more contributors. Contrast to flake8
which is newer, and to achieve the desired behavior it is necessary to install 3rd party plugins/libraries that might be abandoned in a year or two or break when flake8
upgrades. Either scenario is problematic with the latter being troublesome if you're not careful with mentioning specific version/builds in CI pipelines.