Peque
Peque

Reputation: 14801

Python: docstrings and type annotations

Having a function like:

def foo(x: int) -> float:
    return float(x)

I would like to use a NumPy-like docstring like the following:

def foo(x: int) -> float:
    """
    Parameters
    ----------
    x
        Input parameter

    Returns
    -------
    The output value.
    """
    return float(x)

Note that:

Is there a Sphinx extension that supports that? Would you recommend another syntax?

Upvotes: 14

Views: 4893

Answers (1)

phd
phd

Reputation: 94473

Standard extension is autodoc. Napoleon extension supports Google- and NumPy-style docstrings.

Upvotes: 3

Related Questions