docformatter is a Python tool that automatically formats docstrings to adhere to PEP 257 conventions, ensuring consistent and readable documentation. It handles various aspects like summary line wrapping, blank lines, and multi-line docstring structure. The library is actively maintained, with frequent releases addressing bug fixes and new features, and its current version is 1.7.7.
pip install docformatterNo compatibility data collected yet for this library.
This quickstart demonstrates how to use `docformatter` programmatically via `subprocess` to format a Python file's docstrings. It creates a temporary file, runs `docformatter --in-place` on it, and then prints the formatted content before cleaning up.
Upgrade to Python 3.9 or newer, or pin `docformatter` to `<1.7.7` in your `requirements.txt`.
Ensure you are on the latest `docformatter` version. Utilize the `--style` option (e.g., `--style sphinx`) if using a specific docstring style. Consider `--force-wrap` for challenging cases, though it might occasionally produce less-than-ideal output for complex lists. Review the formatted output carefully.
Always refer to the latest `docformatter` documentation or its GitHub repository's `.pre-commit-config.yaml` for the recommended `rev` and `args`. Ensure you include `--in-place` if you want the hook to modify files directly, or `--check` if you only want it to report issues without changing files. Run `pre-commit autoupdate` regularly.
Upgrade to `docformatter` version 1.7.0 or newer to use the `--black` option for improved compatibility. Always run `docformatter` before `black` in your formatting pipeline if both are used.
Upgrade docformatter to a version compatible with your Python interpreter, or ensure that Python version is compatible with docformatter's dependencies. For Python 3.14 and untokenize, a docformatter release that drops or vendors 'untokenize' is needed.
Update the integrating code or script to use the current docformatter API, such as invoking it via its command-line interface or using the updated programmatic API if available. This function was removed in docformatter version 1.5.
Explicitly pass the `--config` argument to docformatter in your `.pre-commit-config.yaml` and add `tomli` to `additional_dependencies` for Python < 3.11. Example: `args: [--in-place, --config, pyproject.toml]`
Upgrade docformatter to a version where this bug has been addressed and fixed (e.g., versions released after the fix for issue #277, which was closed in #304).