My Flake8 Setup
Flake8
is a
linter for Python source code. Out of the box, it
will (mostly) enforce the style guidelines defined in
PEP 8, but its real power comes from its rich list of
plugins. Below is a list of plugins I use when developing
Python projects.
-
flake8-commas
makes sure that all of your lists, dictionaries, function calls, etc. have trailing commas where appropriate. Using this plugin puts an end to noisy diffs and pesky merge conflicts. -
flake8-comprehensions
is one of my favorites lately. It prevents redundant function calls and prefersdict
,list
,set
, andtuple
literals over function calls when possible. Fixes for its warnings nearly always involve deleting code, and the results are more readable and idiomatic. -
flake8-docstrings
enforces the rules listed in PEP 257. At a bare minimum, code should be documented – enough said. -
flake8-per-file-ignores
allows developers to more granularly configure suppressedFlake8
warnings. This is especially useful in cases such as autogenerated database migrations (via Django or Alembic) and allowing unused imports inside of__init__.py
files.
I’m sure I’m missing plenty of plugins from this list, and I’m constantly tweaking my configuration. I’m also working on replacing linters with automatic formatters such as yapf and isort where possible. From time to time, I’ll update this post with any noteworthy additions.