我一直试图记录基于MongoEngine的应用程序,但在记录文档类的属性时遇到问题。
我采用了正确的语法,如下所示:
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描述)
我错过狮身人面像分机了吗?还是我把语法搞砸了?
结果发现这个问题是由其他原因引起的,除了mzjn的答案之外:我必须完全限定我正在工作的类,因为我为
..currentmodule::
指定的模块正在导入,使用了from x import y
语法,即以下语法工作:长话短说:检查您的进口!
要将类的成员放入文档中,请使用
:members:
选项:如果没有
:members:
,则插入only the class docstring。另请参见^{} 配置选项。
使用
autoattribute
和不使用:members:
可以得到与上面相同的结果(注意缩进):我无法重现使用StringField中的docstring记录
uri
属性的问题。我用的是狮身人面像1.2.2。
相关问题 更多 >
编程相关推荐