[英]How to document a single private attribute with Sphinx autodoc?
I'm using sphinx and the autodoc extension to automatically generate documentation from docstrings in my python modules. 我正在使用sphinx和autodoc扩展名从我的python模块中的文档字符串自动生成文档。
I currently using the automodule
directive to document all the public members of the module 我目前正在使用
automodule
指令来记录模块的所有公共成员
.. automodule::
:members:
My module also has a number of private attributes. 我的模块还具有许多私有属性。 I'd like to include one of them in the documentation.
我想在文档中包括其中之一。
Is there a way to tell automodule
to document all public members and also this one private member? 有没有办法告诉自动
automodule
记录所有公共成员以及这个私有成员的文件? I've tried using the :private-members:
option, but that includes all private members. 我尝试使用
:private-members:
选项,但这包括所有私有成员。 I've also tried manually specifying the private attribute, but then it doesn't document any of the public members. 我也尝试过手动指定private属性,但是它没有记录任何公共成员。
.. automodule::
:members: _PRIVATE_ATTR
I'd like to avoid having to manually list every single public member just to add this one private member. 我想避免只为添加此私人成员而手动列出每个公共成员的方法。
Is there a way to do this with autodoc? 有没有办法用autodoc做到这一点?
Here is what I would expect to work (tested with Sphinx 1.8.3): 这是我期望的工作(使用Sphinx 1.8.3测试):
.. automodule:: yourmodule
:members:
:private-members: _PRIVATE_ATTR
But it does not quite work. 但这并不完全有效。 If the
:private-members:
option is given, with or without arguments, all private members are included (provided that they have a docstring). 如果给出了
:private-members:
选项(带或不带参数),则包括所有私有成员(前提是它们具有文档字符串)。
The :special-members:
option takes arguments, so it is strange that :private-members:
doesn't. :special-members:
选项接受参数,所以奇怪的是:private-members:
没有。
Instead you can use autodata
: 相反,您可以使用
autodata
:
.. automodule:: yourmodule
:members:
.. autodata:: yourmodule._PRIVATE_ATTR
Here is a slightly different alternative with autodata
"inside of" automodule
: 这是在
autodata
内部的automodule
另一种替代方法:
.. automodule:: yourmodule
:members:
.. autodata:: _PRIVATE_ATTR
There is also an autoattribute
directive but it does not work with module-level "data members". 还有一个
autoattribute
指令,但是它不适用于模块级的“数据成员”。 I have found that autoattribute
can be used to document private class attributes , but the documentation is not clear on the exact difference between autodata
and autoattribute
. 我发现可以使用
autoattribute
来记录私有类属性 ,但是对于 autodata
和autoattribute
之间的确切区别, 该文档尚不清楚。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.