簡體   English   中英

Sphinx類屬性文檔

[英]Sphinx class attribute documentation

我一直在嘗試記錄基於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: , 插入類docstring

另請參見autodoc_default_flags配置選項。


您可以使用autoattribute獲得與上面相同的結果,並且不使用:members:注意縮進):

.. autoclass:: Asset

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

我無法重現使用StringField的docstring記錄uri屬性的問題。

我正在使用Sphinx 1.2.2。

事實證明這個問題是由於mzjn的回答而引起的:我必須完全限定類我是..autoclass:: ing因為我為..currentmodule::指定的模塊導入使用了from x import y語法,即以下語法有效:

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

長話短說: 檢查你的進口!

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM