Formats docstrings to follow PEP 257
Project description
Code |
|
Docstrings |
|
GitHub |
|
PyPi |
|
Formats docstrings to follow PEP 257.
Features
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):
$ pip install git+https://github.com/PyCQA/docformatter.git@<RC_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."""
def launch_rocket():
"""Launch
the
rocket. Go colonize space."""
def factorial(x):
'''
Return x factorial.
This uses math.factorial.
'''
import math
return math.factorial(x)
def print_factorial(x):
"""Print x factorial"""
print(factorial(x))
def main():
"""Main
function"""
print_factorial(5)
if factorial(10):
launch_rocket()
gets formatted into this
"""Here are some examples.
This module docstring should be dedented.
"""
def launch_rocket():
"""Launch the rocket.
Go colonize space.
"""
def factorial(x):
"""Return x factorial.
This uses math.factorial.
"""
import math
return math.factorial(x)
def print_factorial(x):
"""Print x factorial."""
print(factorial(x))
def main():
"""Main function."""
print_factorial(5)
if factorial(10):
launch_rocket()
Marketing
Do you use docformatter? What style docstrings do you use? Add some badges to your project’s README and let everyone know.
.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
:target: https://github.com/PyCQA/docformatter
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
:target: https://www.sphinx-doc.org/en/master/usage/index.html
.. image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
:target: https://numpydoc.readthedocs.io/en/latest/format.html
.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
:target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings
Issues
Bugs and patches can be reported on the GitHub page.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file docformatter-1.7.4.tar.gz
.
File metadata
- Download URL: docformatter-1.7.4.tar.gz
- Upload date:
- Size: 25.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e1897e316016debf3fdee3e0515e54faaaef32ef84efbd2fbbb03bf9198238c |
|
MD5 | fc107057483b80f4fa0c815bb759edb3 |
|
BLAKE2b-256 | b852834e31b25d6a493da6b3cfeb2364aeeb07f8c5788d3ace7f7808a0c58d8d |
File details
Details for the file docformatter-1.7.4-py3-none-any.whl
.
File metadata
- Download URL: docformatter-1.7.4-py3-none-any.whl
- Upload date:
- Size: 32.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.2 CPython/3.11.2
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e91f99772562f583723272180deab65940bceec65570a3f2ab72695e80d9d4d0 |
|
MD5 | 63fb1bb956acfbb38e0b05383daece4c |
|
BLAKE2b-256 | 84b21844950043f108297b5dba1adcf675407977acc5f2622f5e0c0072822d00 |