iTa*_*ayb 9 python python-sphinx autodoc
我有以下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
'''
Run Code Online (Sandbox Code Playgroud)
有没有办法告诉sphinx如果可用,将"Default is X"部分添加到参数的描述中?
小智 5
我已经采用了 Voy 的答案并制作了一个包,可以自动为您执行此操作。非常欢迎您尝试并报告问题。
下面的代码
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'
pass
Run Code Online (Sandbox Code Playgroud)
如果使用默认主题,将像这样呈现,并且像这样使用sphinx_rtd_theme.
defaults to是现在的关键词。请参阅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]
"""
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
1434 次 |
| 最近记录: |