Skip to main content

Formats docstrings to follow PEP 257

Project description

Code

BLACK ISORT

Docstrings

SELF NUMPSTYLE

GitHub

CI CONTRIBUTORS COMMIT PRE

PyPi

VERSION LICENSE PYVERS PYMAT DD

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 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):
        print_factorial(22)

gets formatted into this

"""Here are some examples.

This module docstring should be dedented.
"""

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):
        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.

SELF

.. image:: https://img.shields.io/badge/%20formatter-docformatter-fedcba.svg
    :target: https://github.com/PyCQA/docformatter

SPHINXSTYLE

.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
    :target: https://www.sphinx-doc.org/en/master/usage/index.html

NUMPSTYLE

.. image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
    :target: https://numpydoc.readthedocs.io/en/latest/format.html

GOOGSTYLE

.. image:: https://img.shields.io/badge/%20style-google-3666d6.svg
    :target: https://google.github.io/styleguide/pyguide.html#s3.8-comments-and-docstrings

Assistance

docformatter has an IRC channel on Libera.Chat in the #docformatter room.

There is no docformatter channel on the Python Code Quality Discord server, but you can ask for help in the # general channel.

Issues

Bugs and patches can be reported on the GitHub page.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

docformatter-1.7.8.tar.gz (37.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

docformatter-1.7.8-py3-none-any.whl (59.4 kB view details)

Uploaded Python 3

File details

Details for the file docformatter-1.7.8.tar.gz.

File metadata

  • Download URL: docformatter-1.7.8.tar.gz
  • Upload date:
  • Size: 37.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.12 Linux/6.19.10-100.fc42.x86_64

File hashes

Hashes for docformatter-1.7.8.tar.gz
Algorithm Hash digest
SHA256 6589b62a8f38c62c4c8c84cb1afa296af007c88c959e4c9d25c74c1f933c4dbf
MD5 912a3e7b5e51f162e1caedd996cfb6c8
BLAKE2b-256 6ae1f6fb315205e0a8f62ddbd52029b3d39cb5bada768af317193460f0454f6b

See more details on using hashes here.

File details

Details for the file docformatter-1.7.8-py3-none-any.whl.

File metadata

  • Download URL: docformatter-1.7.8-py3-none-any.whl
  • Upload date:
  • Size: 59.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.3.4 CPython/3.13.12 Linux/6.19.10-100.fc42.x86_64

File hashes

Hashes for docformatter-1.7.8-py3-none-any.whl
Algorithm Hash digest
SHA256 8e518948bacb8d8df5d5f625060e214a200f0a908d8e6797c9ebbdd2cdd17467
MD5 c81a76284093a4f4ce5273ac6650f4f2
BLAKE2b-256 099b9d2f60e967243aa0d1c6366f4f5feb0740393b5da7dbc66802034afc6331

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page