狮身人面像包括私人属性,即使没有指示
我没有在任何地方包括:private-Members:
选项,但是Sphinx仍然在课堂文档中包含私人属性。我在做什么错?
MWE:
mypackage/foo.py
:
class MyClass(object):
"""A class.
Attributes
----------
attr1 : float
Attribute 1.
attr2 : float
Attribute 2.
_private1 : float
Private attribute 1.
_private2 : float
Private attribute 2.
"""
pass
index.rst
:
.. toctree::
:maxdepth: 2
:caption: Table of Contents
foo
foo.rst
:
``foo`` Module
==============
.. automodule:: mypackage.foo
:members:
conf.py
:
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
]
source_suffix = '.rst'
master_doc = 'index'
language = 'en'
渲染html :
I did not include the :private-members:
option anywhere, but Sphinx still includes private attributes in the docs for the class. What am I doing wrong?
MWE:
mypackage/foo.py
:
class MyClass(object):
"""A class.
Attributes
----------
attr1 : float
Attribute 1.
attr2 : float
Attribute 2.
_private1 : float
Private attribute 1.
_private2 : float
Private attribute 2.
"""
pass
index.rst
:
.. toctree::
:maxdepth: 2
:caption: Table of Contents
foo
foo.rst
:
``foo`` Module
==============
.. automodule:: mypackage.foo
:members:
conf.py
:
# -*- coding: utf-8 -*-
#
# Configuration file for the Sphinx documentation builder.
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
]
source_suffix = '.rst'
master_doc = 'index'
language = 'en'
Rendered html:
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
缺少
:私人会员:
仅对狮身人面像通过解析Python代码找到的成员生效。例如:在这种情况下,它不会记录
_private1
和_private2
(没有:private>:private-Members:
)。但是,在您的情况下,
_private1
和_private2
只是文档字符串中的文本。我怀疑在这种情况下,狮身人面像知道它们是班级的属性。The absence of
:private-members:
only takes effect for members that sphinx finds by parsing the Python code. For example:In this case, it won't document
_private1
and_private2
(without:private-members:
).In you case, however,
_private1
and_private2
are just text inside a doc string. I doubt even that sphinx in that case knows that they are attributes of the class.