gpt4 book ai didi

python - 是否可以在 Sphinx 中隐藏 Python 函数参数?

转载 作者:太空狗 更新时间:2023-10-29 17:19:14 25 4
gpt4 key购买 nike

假设我有以下记录在 Numpydoc style 中的函数, 并且文档是使用 Sphinx 自动生成的autofunction directive :

def foo(x, y, _hidden_argument=None):
"""
Foo a bar.

Parameters
----------
x: str
The first argument to foo.
y: str
The second argument to foo.

Returns
-------
The barred foo.

"""
if _hidden_argument:
_end_users_shouldnt_call_this_function(x, y)
return x + y

我不想将隐藏参数作为我的公共(public) API 的一部分进行宣传,但它会出现在我自动生成的文档中。有什么方法可以告诉 Sphinx 忽略函数的特定参数,或者(甚至更好)让它自动忽略带有前导下划线的参数?

最佳答案

我认为在 Sphinx 中没有这样的选项。无需破解代码即可实现此目的的一种可能方法是使用自定义签名。

在这种情况下,你需要这样的东西:

.. autofunction:: some_module.foo(x, y)

这将覆盖函数的参数列表并在文档中隐藏不需要的参数。

关于python - 是否可以在 Sphinx 中隐藏 Python 函数参数?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30542590/

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