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.

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:

$ pip install --upgrade docformatter[tomli]

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.

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

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.0.tar.gz (23.3 kB view details)

Uploaded Source

Built Distribution

docformatter-1.7.0-py3-none-any.whl (29.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docformatter-1.7.0.tar.gz
  • Upload date:
  • Size: 23.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for docformatter-1.7.0.tar.gz
Algorithm Hash digest
SHA256 13bc8805b3bf4f8a0911fe87c3ea58c7bfc0d5739a2d86bb339efab3932ae49b
MD5 50d441827369616c3d8eed1e975354fb
BLAKE2b-256 ebe0194b10a4697569d242fd3f8b71477664fcb7e89c8bf7e30ece387a34432d

See more details on using hashes here.

File details

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

File metadata

  • Download URL: docformatter-1.7.0-py3-none-any.whl
  • Upload date:
  • Size: 29.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.2

File hashes

Hashes for docformatter-1.7.0-py3-none-any.whl
Algorithm Hash digest
SHA256 8099de46392970f63eacfc69143b23dd78f6d6511ff8e9f474aba70f80d2e312
MD5 19cade335478ec5e8f2780d3bf8d18e9
BLAKE2b-256 6713258f94a8e20f975a27a243c860591aeeb5f8a34bdc5be82e8d68be87ddc1

See more details on using hashes here.

Supported by

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