Flake8 not giving errors/warnings on missing docstring or code not following PEP8 naming convention
Asked Answered
A

1

11

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

Argil answered 25/2, 2020 at 21:37 Comment(0)
A
11

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.

Argil answered 26/2, 2020 at 2:18 Comment(4)
genuinely curious what you possibly mean by "it's for the fanboys" (I'm the current maintainer) -- flake8 and its plugin ecosystem are some of the most depended on projects in the python ecosystemQuintana
Anthony - very nice of you to drop in here and leave a comment I appreciate it. I updated my comment about fanboys as it may be interpreted as having a negative connotation, I would have preferred to use the word "enthusiast". Just trying to bring up the point that as of today the flake8 ecosystem is newer and relies on plugins to achieve common behavior found in Pylint. I feel this plugin ecosystem works only if the community support is there for plugin development.Argil
when you say "newer" -- you realize both have been around for >10 years right? pyflakes and pylint both appeared around mid-late 2004. the reason you see fewer commits in flake8 is because flake8 itself does not implement checks but builds a strong foundation for a plugin ecosystem. historically flake8 has >25% more downloads than pylint. I'm not saying pylint is bad/worse but your assessment seems quite short sighted :)Quintana
Anthony can't argue with the numbers you present there. I agree - I'll be exploring flake8 more before I jump to conclusionsArgil

© 2022 - 2024 — McMap. All rights reserved.