PyDocLint
PyDocLint is a fast Python docstring linter that verifies whether a function's docstring sections (arguments, returns, yields, and raises) accurately match its signature and implementation. It currently supports NumPy, Google, and Sphinx docstring styles, running significantly faster than older alternatives. The library is actively maintained with frequent releases, and its current version is 0.8.3.
Warnings
- breaking Python 3.9 support was dropped in version 0.7.4. Users on older Python versions will need to upgrade their Python environment to at least 3.10 to use pydoclint 0.7.4 and newer.
- gotcha Configuration file validation was enhanced in version 0.7.4. Previously, malformed `pyproject.toml` or other config files might have been silently ignored or partially applied. Now, invalid configurations might lead to errors.
- gotcha Earlier versions (prior to approximately 0.7.0) primarily supported NumPy-style docstrings, with Google and Sphinx style support added later. Users expecting full support for Google or Sphinx styles should ensure they are on a recent version.
- gotcha PyDocLint performs static analysis and expects exact matches for type hints between docstrings and function signatures. It does not recognize conventions like 'int, optional' for `Optional[int]`, requiring verbatim matching. Also, non-standard Pythonic naming (e.g., renaming `classmethod`) might lead to unexpected linting results.
Install
-
pip install pydoclint -
pip install pydoclint[flake8]
Quickstart
# my_module.py
def my_function(arg1: int, arg2: str) -> None:
"""
A sample function.
Parameters
----------
arg1 : int
The first argument.
arg2 : str
The second argument.
"""
print(f'{arg1}, {arg2}')
# pyproject.toml
[tool.pydoclint]
style = "numpy"
check-arg-order = true
# Terminal
# Run pydoclint on a file or folder
pydoclint my_module.py
# Or with a config file
pydoclint --config=pyproject.toml my_module.py
# Or as a pre-commit hook (add to .pre-commit-config.yaml)
# - repo: https://github.com/jsh9/pydoclint
# rev: <latest_tag> # e.g., 0.8.3
# hooks:
# - id: pydoclint
# args: ["--config=pyproject.toml"]