Skip to main content

Formats docstrings to follow PEP 257

Project description

Code

BLACK ISORT

Docstrings

SELF DOCSTYLE

GitHub

CI CONTRIBUTORS COMMIT

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]

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

DOCSTYLE

.. image:: https://img.shields.io/badge/%20style-numpy-459db9.svg
  :target: https://numpydoc.readthedocs.io/en/latest/format.html
https://img.shields.io/badge/%20style-sphinx-0a507a.svg
.. image:: https://img.shields.io/badge/%20style-sphinx-0a507a.svg
    :target: https://www.sphinx-doc.org/en/master/usage/index.html

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.5.1.tar.gz (19.0 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.5.1-py3-none-any.whl (24.6 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: docformatter-1.5.1.tar.gz
  • Upload date:
  • Size: 19.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.8 Linux/5.15.19

File hashes

Hashes for docformatter-1.5.1.tar.gz
Algorithm Hash digest
SHA256 3fa3cdb90cdbcdee82747c58410e47fc7e2e8c352b82bed80767915eb03f2e43
MD5 415f70ecf39d254f6ae97a5ab2bedff9
BLAKE2b-256 1c5b337824ecca1b5a593cd96aa3404ac7e6d7fa65ae750d94c0e57e255b6168

See more details on using hashes here.

File details

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

File metadata

  • Download URL: docformatter-1.5.1-py3-none-any.whl
  • Upload date:
  • Size: 24.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.10.8 Linux/5.15.19

File hashes

Hashes for docformatter-1.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 05d6e4c528278b3a54000e08695822617a38963a380f5aef19e12dd0e630f19a
MD5 3a2372e2ecf148602ad6e593bd8feb88
BLAKE2b-256 8121ffe70580b217d1e6c7ca5f3e67b050abf750d312d5403c6b4463074d1aeb

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