防止 Sphinx 显示 python 函数参数默认值
在包中,我在 __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 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论