flake8-docstrings
flake8-docstrings is an extension for the `flake8` linter that integrates `pydocstyle` to enforce PEP 257 docstring conventions and other common docstring styles. It allows developers to check for issues like missing docstrings, incorrect formatting, and adherence to specific style guides (e.g., Google, NumPy) directly within their `flake8` workflow. The current stable version is 1.7.0, and it maintains an active release cadence.
Warnings
- breaking Older versions of `flake8-docstrings` (before 1.0.0) supported Python 2.7. Modern versions, including 1.7.0, require Python 3.8 or later.
- gotcha `flake8-docstrings` acts as a wrapper for `pydocstyle`. While `flake8-docstrings` integrates `pydocstyle` into `flake8`, the actual docstring checks and their error codes (e.g., D100, D205) originate from `pydocstyle`. Issues with specific docstring check logic or behavior should often be reported to the `pydocstyle` project.
- gotcha By default, `pydocstyle` (and thus `flake8-docstrings`) enforces PEP 257. If your project uses other docstring conventions like Google or NumPy style, you must explicitly configure `flake8` with `--docstring-convention google` or `--docstring-convention numpy`. Without this, non-PEP 257 compliant docstrings will trigger many errors.
- gotcha When using `docstring-convention = all` (which enables all `pydocstyle` rules), you might encounter conflicting checks, as `pydocstyle` itself defines some mutually exclusive rules. This will lead to many false positives or undesirable warnings.
Install
-
pip install flake8-docstrings
Quickstart
# my_module.py
def my_function(arg):
"""This is a missing docstring summary.
:param arg: An argument.
:return: None
"""
pass
# Configure in setup.cfg, .flake8, or tox.ini
# [flake8]
# docstring-convention = google
# extend-ignore = D205,D212,D415 # Common ignores for Google style
# Run flake8 from your terminal
# $ flake8 my_module.py