Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Make sphinx's autodoc show default values in parameters' description

I have the following docstring:

def progress_bar(progress, length=20):
    '''
    Returns a textual progress bar.

    >>> progress_bar(0.6)
    '[##########--------]'

    :param progress: Number between 0 and 1 describes the progress.
    :type progress: float
    :param length: The length of the progress bar in chars. Default is 20.
    :type length: int
    :rtype: string
    '''

Is there a way to tell sphinx to add the "Default is X" part to the parameters' description if available?

like image 880
iTayb Avatar asked Jun 29 '13 13:06

iTayb


1 Answers

defaults to is the keyword now. See https://github.com/sglvladi/Sphinx-RTD-Tutorial/blob/a69fd09/docs/source/docstrings.rst#the-sphinx-docstring-format

"""[Summary]

:param [ParamName]: [ParamDescription], defaults to [DefaultParamVal]
:type [ParamName]: [ParamType](, optional)
...
:raises [ErrorType]: [ErrorDescription]
...
:return: [ReturnDescription]
:rtype: [ReturnType]
"""
like image 55
Samuel Marks Avatar answered Oct 04 '22 02:10

Samuel Marks