Skip to main content

Formats docstrings to follow PEP 257.

Project description

Formats docstrings to follow PEP 257.

Build status

Features

docformatter currently 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.

  • The BDFL recommends inserting a blank line between the last paragraph in a multi-line docstring and its closing quotes, placing the closing quotes on a line by themselves.

Example

After running:

$ docformatter example.py

this code:

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:

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()

Options

Below is the help output:

usage: docformatter [-h] [--in-place] [--no-backup]
                    [--wrap-long-summaries LENGTH] [--version]
                    files [files ...]

Formats docstrings to follow PEP 257.

positional arguments:
  files                 files to format

optional arguments:
  -h, --help            show this help message and exit
  --in-place            make changes to files instead of printing diffs
  --no-backup           do not write backup files
  --wrap-long-summaries LENGTH
                        wrap long summary lines at this length (default: 0)
  --version             show program's version number and exit

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

Uploaded Source

File details

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

File metadata

File hashes

Hashes for docformatter-0.1.8.tar.gz
Algorithm Hash digest
SHA256 b59e4cc4d39f900511744939c249aaadc0dcc442b53e7c83bdc867a124a7bc19
MD5 201a45e32d2d0454f879baab4b9f4dec
BLAKE2b-256 44020c52bde8db8049aeb4a430ce6eaac941dde9bcda6b6ef1a524f532fdbb39

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