【发布时间】:2019-06-20 21:02:29
【问题描述】:
我发现了相互矛盾且经常过时的信息,因此希望有人能解决这个问题。
我想用 Sphinx 记录这样的事情:
class MyClass:
"""
MyClass, which is documented with a docstring at the class level
"""
classVar = None
"""A class var with an initial value and a 1-line doc"""
def __init__(self):
"""
__init__'s docs
"""
instanceVar1 = 10
"""An instance var with an initial val and 1-line doc"""
#: An instance var with an initial val and a doc-comment
instanceVar2 = 10
在我的文档中,我希望看到 instanceVar1 及其文档字符串(最好使用其默认值,但我会对描述感到满意)。但是,如果我使用以下第一个文件运行:
.. automodule:: mymodule.mycode
:members:
谷歌搜索给了我关于什么应该/不应该起作用的相互矛盾的信息。一些较旧的堆栈溢出链引用了实例属性的自动文档问题(例如here),但如果您像我上面所做的那样添加了文档字符串,它们也会引用它。 Sphinx 文档引用了all attributes can be autodocumented。
任何人都可以评论我正在尝试做的事情是否应该工作/它现在对他们有用吗/关于我可能搞砸的建议?谢谢。
【问题讨论】:
-
也许我遗漏了一些东西,但这不是here 描述的用于 bar、baz、quz 和 spam 的格式吗?
-
Automodule 只会使用文档字符串,你真的使用自动属性吗? FWIW 我通常使用sphinx-doc.org/en/master/usage/extensions/napoleon.html 以获得更易于阅读的源代码。
标签: python python-sphinx autodoc