Skip to main content

Automatic generation of default arguments for the Sphinx autodoc extension.

Project description

sphinx-autodoc-defaultargs

PyPi Version Build Status Coverage Status License Python Versions

Overview

This extension automatically generates default arguments for the Sphinx autodoc extension.

Example

With this package, the default values of all documented arguments, and undocumented arguments if enabled, are automatically detected and added to the docstring.

It also detects existing documentation of default arguments with the text unchanged.

def func(x=None, y=None):
    """
    Example docstring.

    :param x: The default value ``None`` will be added here.
    :param y: The text of default value is unchanged.
              (Default: ``'Default Value'``)
    """

    if y is None:
        y = 'Default Value'

    ...

Installation

pip

If you use pip, you can install the package with:

python -m pip install sphinx_autodoc_defaultargs

setup.py

In the root directory, run the following command in the terminal.

python setup.py install

Usage

Add the extension as well as the global substitution to the conf.py file:

extensions = [
    'sphinx.ext.autodoc',
    'sphinx_autodoc_defaultargs'
]

rst_prolog = """
.. |default| raw:: html

    <div class="default-value-section">""" + \
    ' <span class="default-value-label">Default:</span>'

Note that it should be loaded after sphinx.ext.napoleon.

Config Options

  • always_document_default_args (default: False): If False, do not add info of default arguments for undocumented parameters. If True, add stub documentation for undocumented parameters to be able to add default value and to flag optional in the type.

  • docstring_default_arg_flags (default: [('(Default: ', ')')]): List of pairs indicating the header and the footer of an existing documentation of default values, which is expected at the end of the param section. If detected, it will be replaced by the unified style but the text should remain unchanged.

  • docstring_default_arg_after_directives (default: False): If True, the default value will be added after all directives (e.g., note, warning). Existing documentation of the default value is also expected after these directives. Otherwise, it will be added, and expected to exist, before these directives.

  • docstring_default_arg_substitution (default: '|default|'): The substitution markup defined in the conf.py file.

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

sphinx-autodoc-defaultargs-0.1.2.tar.gz (16.7 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file sphinx-autodoc-defaultargs-0.1.2.tar.gz.

File metadata

  • Download URL: sphinx-autodoc-defaultargs-0.1.2.tar.gz
  • Upload date:
  • Size: 16.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for sphinx-autodoc-defaultargs-0.1.2.tar.gz
Algorithm Hash digest
SHA256 b11cd9ac43510c1f1e9a3f9469a370e6bbe2bc2cb9e67cb79987f4dcd3be5be3
MD5 5d7a7652961fb51e5e4bd632e5cc3940
BLAKE2b-256 1a7c8edb5d817ebeb146073be629ed58f89b292a643ee111bee3c703be05a7a1

See more details on using hashes here.

File details

Details for the file sphinx_autodoc_defaultargs-0.1.2-py3-none-any.whl.

File metadata

  • Download URL: sphinx_autodoc_defaultargs-0.1.2-py3-none-any.whl
  • Upload date:
  • Size: 9.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/3.4.1 importlib_metadata/4.0.1 pkginfo/1.7.0 requests/2.25.1 requests-toolbelt/0.9.1 tqdm/4.60.0 CPython/3.9.4

File hashes

Hashes for sphinx_autodoc_defaultargs-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 1513b1aea8c20348f1763dbfd7ff11f86cd77f2ce3246c73e1405a2a67fea3ff
MD5 6878ce894409920cf6c60cac9772f264
BLAKE2b-256 e23fa352e58671b1e6d932a6a4b28b45ff58791788ab7fb6a1f9a7162411198d

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