You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Sphinx numpydoc如何避免Returns被拆分为两个章节?(PyData主题)

解决Sphinx Numpy doc Returns章节被拆分的问题

使用Numpy风格的docstring编写Returns章节时,原格式如下:

Returns
-------
out: float
    A sentence about the return type

但在PyData Sphinx主题下渲染后,会被拆分为两个独立部分:

Returns:

    out - A sentence about the return type

Return type:

    float

想要让Returns章节和Parameters章节保持一致的完整格式,不被拆分,可通过以下方式解决:

  • 修改Sphinx配置文件conf.py,添加或调整numpydoc相关配置:
    numpydoc_show_return_type = False
    

该配置会关闭单独显示返回类型的功能,让Returns章节的内容和Parameters保持一致,将返回变量名、类型、描述整合在同一区块中,避免被拆分为两个独立部分。

内容的提问来源于stack exchange,提问作者Hielke Walinga

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.16 15:14:48