防止 Sphinx 显示 python 函数参数默认值

发布于 2025-01-14 04:54:41 字数 578 浏览 2 评论 0原文

在包中,我在 __init__.py 中将全局变量 MyPackage.Data_path 定义为:

Data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'database')

该变量是我的包中多个函数的默认参数。当我使用 Sphinx 编译自动文档时,变量会自动转换为其值(路径字符串),但我只需要在文档中打印其名称。

Sphinx 当前在文档中打印的内容:

download_data(data_dir='/mnt/home/UserName/Path/to/data', ...)

我需要 Sphinx 在文档中打印的内容:

download_data(data_dir=MyPackage.Data_path, ...)

我已尝试使用 :meta hide-value: 但它不起作用(也许我没有正确使用它)。 我知道最好的方法应该是不要有类似的变量,但此时改变它非常复杂。我计划尽快做。

In a package, I define a global variable MyPackage.Data_path in the __init__.py as:

Data_path = os.path.join(os.path.dirname(os.path.abspath(__file__)), 'database')

This variable is the default argument for multiple functions in my package. When I compile the automatic documentation with Sphinx, the variable is automatically converted into its value (the path string), but I need its name only to be printed in the documentation.

What Sphinx currently prints in the docs:

download_data(data_dir='/mnt/home/UserName/Path/to/data', ...)

What I need Sphinx to print in the docs:

download_data(data_dir=MyPackage.Data_path, ...)

I have tried with :meta hide-value: but it does not work (maybe I didn't use it right).
I know the best way should be not to have a similar variable, but it's very complex to change in this moment. I am planning on doing it ASAP.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文