You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
docformatter automatically formats docstrings to follow a subset of the PEP
257 conventions. Below are the relevant items quoted from PEP 257.
For consistency, always use triple double quotes around docstrings.
Triple quotes are used even though the string fits on one line.
Multi-line docstrings consist of a summary line just like a one-line
docstring, followed by a blank line, followed by a more elaborate
description.
Unless the entire docstring fits on a line, place the closing quotes
on a line by themselves.
docformatter also handles some of the PEP 8 conventions.
Don't write string literals that rely on significant trailing
whitespace. Such trailing whitespace is visually indistinguishable
and some editors (or more recently, reindent.py) will trim them.
docformatter formats docstrings compatible with black when passed the
--black option.
docformatter formats field lists that use Epytext or Sphinx styles.
See the the full documentation at read-the-docs, especially the
requirements section for a more detailed discussion of PEP 257 and other
requirements.
Installation
From pip:
$ pip install --upgrade docformatter
Or, if you want to use pyproject.toml to configure docformatter and you're using
Python < 3.11:
$ pip install --upgrade docformatter[tomli]
With Python >=3.11, tomllib from the standard library is used.
Or, if you want to use a release candidate (or any other tag):
Where <RC_TAG> is the release candidate tag you'd like to install. Release
candidate tags will have the format v1.6.0-rc1 Release candidates will also be
made available as a Github Release.
Example
After running:
$ docformatter --in-place example.py
this code
""" Here are some examples. This module docstring should be dedented."""deffactorial(x):
''' Return x factorial. This uses math.factorial. '''importmathreturnmath.factorial(x)
defprint_factorial(x):
"""Print x factorial"""print(factorial(x))
defmain():
"""Main function"""print_factorial(5)
iffactorial(10):
print_factorial(22)
gets formatted into this
"""Here are some examples.This module docstring should be dedented."""deffactorial(x):
"""Return x factorial. This uses math.factorial. """importmathreturnmath.factorial(x)
defprint_factorial(x):
"""Print x factorial."""print(factorial(x))
defmain():
"""Main function."""print_factorial(5)
iffactorial(10):
print_factorial(22)
Marketing
Do you use docformatter? What style docstrings do you use? Add some badges to your project's README and let everyone know.