狮身人面像类属性文件

我一直在试图记录我的基于MongoEngine的应用程序,但是我在处理Document类的文档时遇到了问题。

我采取了正确的语法来做到这一点如下:

class Asset(Document):
     #: This is the URI of the document
     uri = StringField()

我已经尝试过记录我找到的这些属性的各种方法,甚至添加了不属于MongoEngine字段的属性,以确保这不是问题:

class Asset(Document):
    """
    The representation of a file uploaded into the data store.
    """

    #: This is a test attribute.
    foo = 'bar'
    """baz?"""

    #: This is a URI.
    uri = StringField(required=True)
    """This is a URI """

我已经在相应的.rst文件中尝试过各种指令组合。 目前看起来像这样:

.. currentmodule:: mymodule.asset
.. autoclass:: Asset
.. autoattribute:: Asset.foo
.. autoattribute:: Asset.uri

输出结果并不令人满意:foo属性根本没有显示任何文档,而uri字段有MongoEngine的“一个unicode字符串字段”。 (StringField类的文档)作为文档。 此外,属性文档不会放在类的“下方”(就像automodule +:members: - 它使用MongoEngine描述输出所有字段)

我错过狮身人面像延伸? 或者我搞砸了语法?


要将类的成员放入文档中,请使用:members:选项:

.. autoclass:: Asset
   :members:

如果没有:members: :,只会插入类文档字符串。

另请参阅autodoc_default_flags配置选项。


您可以使用autoattribute获取与上面相同的结果,而不使用:members:注意缩进):

.. autoclass:: Asset

   .. autoattribute:: foo
   .. autoattribute:: uri

我无法重现使用StringField中的docstring记录uri属性的问题。

我正在使用狮身人面像1.2.2。


事实证明,这个问题是由于mzjn的其他答案造成的:我不得不完全限定我是..autoclass:: ing的类,因为我为..currentmodule::指定的模块导入使用了from x import y语法,即以下语法工作:

.. currentmodule: mymodule.asset
.. autoclass: mymodule.asset.Asset
   :members:

长话短说: 检查你的进口!

链接地址: http://www.djcxy.com/p/84123.html

上一篇: Sphinx class attribute documentation

下一篇: Python Sphinx: Documentation main page like in Python doc or Sphinx doc