gpt4 book ai didi

python - 使 sphinx 的 autodoc 在参数描述中显示默认值

转载 作者:太空狗 更新时间:2023-10-29 20:30:43 25 4
gpt4 key购买 nike

我有以下文档字符串:

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
'''

有没有办法告诉 sphinx 将“默认为 X”部分添加到参数描述中(如果可用)?

最佳答案

我采纳了 Voy 的回答并做了一个 package它会自动为你做这件事。非常欢迎您尝试并报告问题。

下面的代码

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

将呈现为 this如果使用默认主题,喜欢 this使用 sphinx_rtd_theme

关于python - 使 sphinx 的 autodoc 在参数描述中显示默认值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17380701/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com