cnu*_*cnu 25 python documentation python-sphinx
我正在使用Sphinx来记录我的python项目.我启用了autodoc扩展,并在我的文档中包含以下内容.
.. autoclass:: ClassName
:members:
Run Code Online (Sandbox Code Playgroud)
问题是,它只记录了类中的非私有方法.我如何包含私有方法?
mar*_*omo 27
若您使用的是sphinx 1.1或以上,请访问sphinx文档网站http://www.sphinx-doc.org/en/master/ext/autodoc.html,
:special-members:
:private-members:
Run Code Online (Sandbox Code Playgroud)
解决这个问题的一种方法是明确强制Sphinx记录私人成员.您可以通过附加automethod到类级别文档的末尾来执行此操作:
class SmokeMonster(object):
"""
A large smoke monster that protects the island.
"""
def __init__(self,speed):
"""
:param speed: Velocity in MPH of the smoke monster
:type speed: int
.. document private functions
.. automethod:: _evaporate
"""
self.speed = speed
def _evaporate(self):
"""
Removes the smoke monster from reality. Not to be called by client.
"""
pass
Run Code Online (Sandbox Code Playgroud)
小智 8
您可以将其添加到conf.py文件中:
autodoc_default_flags = ['members', 'undoc-members', 'private-members', 'special-members', 'inherited-members', 'show-inheritance']
Run Code Online (Sandbox Code Playgroud)