我在任何地方都没有包括:private-members:选项,但是狮身人面像仍然在类的文档中包含私有属性。我做错了什么?
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.
"""
passindex.rst
.. toctree::
:maxdepth: 2
:caption: Table of Contents
foofoo.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:

发布于 2022-06-08 13:29:42
缺少:private-members:只对sphinx通过解析Python代码找到的成员生效。例如:
class MyClass(object):
"""A class"""
attr1 = 42 #: Attribute 1.
attr2 = 43 #: Attribute 2.
_private1 = 44 #: Private attribute 1.
_private2 = 45 #: Private attribute 2.在这种情况下,它不会记录_private1和_private2 (没有:private-members:)。
然而,在您的例子中,_private1和_private2只是文档字符串中的文本。我怀疑即使是斯芬克斯在这种情况下,也不知道它们是类的属性。
https://stackoverflow.com/questions/72546256
复制相似问题