Public API

Sphinx extension to show default values in documentation.

Data:

default_regex

Regular expression to match default values declared in docstrings.

no_default_regex

Regular expression to match fields in docstrings to suppress default values.

Functions:

format_default_value(​value)

Format the value as a string.

get_arguments(​obj)

Returns a dictionary mapping argument names to parameters/arguments for a function.

get_class_defaults(​obj)

Obtains the default values for the arguments of a class.

get_function_defaults(​obj)

Obtains the default values for the arguments of a function.

process_default_format(​app)

Prepare the formatting of the default value.

process_docstring(​app, what, name, obj, …)

Add default values to the docstring.

setup(​app)

Setup sphinxcontrib.default_values.

default_regex

Type:    Pattern

Regular expression to match default values declared in docstrings.

Changed in version 0.5.0: Change to be case insensitive.

Pattern

^:(default)[ ]

format_default_value(value)[source]

Format the value as a string.

New in version 0.2.0.

Parameters

value (Any)

Return type

Optional[str]

get_arguments(obj)[source]

Returns a dictionary mapping argument names to parameters/arguments for a function.

Parameters

obj (Callable) – A function (can be the __init__ method of a class).

Return type

Mapping[str, Parameter]

get_class_defaults(obj)[source]

Obtains the default values for the arguments of a class.

Parameters

obj (Type) – The class.

Return type

Iterator[Tuple[str, Any]]

Returns

An iterator of 2-element tuples comprising the argument name and its default value.

get_function_defaults(obj)[source]

Obtains the default values for the arguments of a function.

Parameters

obj (Callable) – The function.

Return type

Iterator[Tuple[str, Any]]

Returns

An iterator of 2-element tuples comprising the argument name and its default value.

no_default_regex

Type:    Pattern

Regular expression to match fields in docstrings to suppress default values.

Changed in version 0.5.0: Change to be case insensitive.

Pattern

^:(no[-_]default)[ ]

process_default_format(app)[source]

Prepare the formatting of the default value.

Parameters

app (Sphinx)

process_docstring(app, what, name, obj, options, lines)[source]

Add default values to the docstring.

Parameters
  • app (Sphinx) – The Sphinx app.

  • what (str)

  • name (str) – The name of the object being documented.

  • obj (Any) – The object being documented.

  • options (Dict[str, Any]) – Mapping of autodoc options to values.

  • lines (List[str]) – List of strings representing the current contents of the docstring.

setup(app)[source]

Setup sphinxcontrib.default_values.

Parameters

app (Sphinx)

Return type

Dict[str, Any]