python-project-template
python-project-template copied to clipboard
Consider `pylint` instead of `flake8`
I think—and I could be wrong, but I’m pretty sure about this—pylint can do everything flake8 does, and more.
As usual for this sort of tool, it’s configurable on a user- and project-basis, and the checks it performs can be further refined on the command line. Multiple output formats exist, including configuration options for tailoring the existing outputs to your liking.
Plus, I just like tools with lint in their name better than tools with flake in their name.
(“Flakes?” Yuck! I’ll admit my code has lint, but I never want to hear that it has flakes! :tongue:)
I took a quick look at pylint's capabilites. From what is mentioned on their site, I'm impressed — I like very strict tools.
It doesn't look like pylint can do complexity checks. That's not a deal-breaker for me, but flake8 can do it (using the mccabe module).
I'd like to try out pylint on a few of my codebases and see how it works. I'll keep you posted.
I took a quick look at pylint's capabilites. From what is mentioned on their site, I'm impressed — I like very strict tools.
Yep!
I also like how pylint lets you do stuff like pylint --disable=C, which disables all Conventions. There are 5 categories in all:
* (C) convention, for programming standard violation
* (R) refactor, for bad code smell
* (W) warning, for python specific problems
* (E) error, for probable bugs in the code
* (F) fatal, if an error occurred which prevented pylint from doing
further processing.
It doesn't look like pylint can do complexity checks. That's not a deal-breaker for me, but flake8 can do it (using the mccabe module).
I don’t know what you mean by “complexity”. I just took a quick look at the mccabe module, but it doesn’t really say how it calculates the complexity—only that it should result in a score less than 10.
Pylint can alert for something that it calls “design”, which points out things like functions that accept too many arguments, classes with too many public attributes, and so on. To see these checks, do pylint --long-help, and look for the options under Design.
Oh! Guess what? I just did pip search pylint, and found the plugin pylint-mccabe! So, you can actually get the same analysis. Shame it’s not built-in—one of my favorite things about pylint is just how much is built-in by defualt—but at least it’s available.
I'd like to try out pylint on a few of my codebases and see how it works. I'll keep you posted.
Cool. I look forward to hearing from you!
P.S.: Also found the plugin git-pylint-commit-hook! I haven’t searched for pylint plugins in a while. Looks like there are some good ones.
You should search for yourself to see if there are any other goodies that appeal to you!
Nice! The metric that the mccabe metric measures is called cyclomatic complexity, which is basically the amount of possible branches in the code. But honestly, code that fails this test is likely to be ugly already and would have probably been refactored by your better-than-average software developer.
Heads up: I'm finishing up my thesis right now so I probably won't have time to try pylint for at least a week.