autoclass 不显示自定义模块名称
Custom module name is not displayed with autoclass
我正在使用 sphinx
构建文档,我的一个 .rst 文件包含以下内容:
############
Internal API
############
.. autoclass:: Individual::Individual
:noindex:
:special-members:
:exclude-members: __weakref__
:member-order: bysource
:members:
.. autoclass:: exceptions::Error
:noindex:
:special-members:
:exclude-members: __weakref__
:member-order: bysource
:members:
.. autoclass:: exceptions::IncorrectValueError
:noindex:
:special-members:
:exclude-members: __weakref__
:member-order: bysource
:members:
构建成功,请看附件截图:
问题是 Individual
class 正确地以 Individual
模块名称为前缀,而后两个 classes 位于 exceptions.py - 不是。为什么会发生这种情况,我该如何解决?
编辑:我在下面添加 conf.py
的内容(没有不必要的部分):
import os
import sys
import sphinx_rtd_theme
sys.path.insert(0, os.path.abspath('../moranpycess'))
extensions = [
'sphinx.ext.napoleon',
'sphinx_rtd_theme',
'recommonmark',
]
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
html_theme = 'sphinx_rtd_theme'
html_show_sourcelink = False
html_static_path = ['_static']
以及exceptions.py
的内容
class Error(Exception):
"""Base class for other exceptions.
Args:
Exception (Exception): built-in Exception class
"""
pass
class IncorrectValueError(Error):
"""Handling incorrect values of user's arguments.
Args:
Error (Error): Base class for other exceptions.
"""
def __init__(
self,
parameter,
message="Please check the documentation for expected argument values.",
):
"""Class initializer.
Args:
parameter (str): parameter name
message (str, optional): error message.
Defaults to "Please check the documentation
for expected argument values.".
"""
self.parameter = parameter
self.message = message
super().__init__(self.message)
def __str__(self):
"""Display the error message.
Returns:
str: error message
"""
return f"Incorrect value for {self.parameter}. {self.message}"
这确实是 sphinx
中保留名称的特例:
https://github.com/sphinx-doc/sphinx/issues/9280
应该会在新版本中修复。
我正在使用 sphinx
构建文档,我的一个 .rst 文件包含以下内容:
############
Internal API
############
.. autoclass:: Individual::Individual
:noindex:
:special-members:
:exclude-members: __weakref__
:member-order: bysource
:members:
.. autoclass:: exceptions::Error
:noindex:
:special-members:
:exclude-members: __weakref__
:member-order: bysource
:members:
.. autoclass:: exceptions::IncorrectValueError
:noindex:
:special-members:
:exclude-members: __weakref__
:member-order: bysource
:members:
构建成功,请看附件截图:
问题是 Individual
class 正确地以 Individual
模块名称为前缀,而后两个 classes 位于 exceptions.py - 不是。为什么会发生这种情况,我该如何解决?
编辑:我在下面添加 conf.py
的内容(没有不必要的部分):
import os
import sys
import sphinx_rtd_theme
sys.path.insert(0, os.path.abspath('../moranpycess'))
extensions = [
'sphinx.ext.napoleon',
'sphinx_rtd_theme',
'recommonmark',
]
templates_path = ['_templates']
exclude_patterns = ['_build', 'Thumbs.db', '.DS_Store']
html_theme = 'sphinx_rtd_theme'
html_show_sourcelink = False
html_static_path = ['_static']
以及exceptions.py
class Error(Exception):
"""Base class for other exceptions.
Args:
Exception (Exception): built-in Exception class
"""
pass
class IncorrectValueError(Error):
"""Handling incorrect values of user's arguments.
Args:
Error (Error): Base class for other exceptions.
"""
def __init__(
self,
parameter,
message="Please check the documentation for expected argument values.",
):
"""Class initializer.
Args:
parameter (str): parameter name
message (str, optional): error message.
Defaults to "Please check the documentation
for expected argument values.".
"""
self.parameter = parameter
self.message = message
super().__init__(self.message)
def __str__(self):
"""Display the error message.
Returns:
str: error message
"""
return f"Incorrect value for {self.parameter}. {self.message}"
这确实是 sphinx
中保留名称的特例:
https://github.com/sphinx-doc/sphinx/issues/9280
应该会在新版本中修复。