【问题标题】:Appengine model property docstringAppengine 模型属性文档字符串
【发布时间】:2013-07-04 14:29:30
【问题描述】:

我正在使用多个 appengine 模型和 autodoc。但是我找不到任何 获取我的文档以应用属性的方式。我正在使用NDB 并使用Sphinx 构建文档。

以模型为例:

class Greeting(ndb.Model):
  """Models an individual Guestbook entry with content and date."""
  content = ndb.StringProperty()
  date = ndb.DateTimeProperty(auto_now_add=True)

生成的内容文档字符串是

一个索引属性,其值为有限长度的文本字符串

我尝试了以下方法:

  "The content"
  content = ndb.StringProperty()

  content = ndb.StringProperty()
  "The content"

  #: the content
  content = ndb.StringProperty()

  content = ndb.StringProperty()
  content.__doc__="The content"

  content = ndb.StringProperty(__doc__="the content")

  content = ndb.StringProperty(doc="the content")

他们都没有给出错误或工作 - 我总是得到“一个索引属性......”。我很惊讶 显式设置 __doc__ 无效。

知道如何使用我自己的文档字符串吗?

【问题讨论】:

  • 不是 Sphinx 方面的专家,但我希望您会在类文档字符串本身中记录这些字段。
  • @DanielRoseman 记录代码中出现的字段是正常的。它适用于普通课程。
  • 真的吗?不是我用过的任何文档格式。我无法在评论中显示它,但作为示例,请参阅 Google Python open-source style guide(向下滚动一点以进入 Classes 小节),其中它们在类级文档字符串中包含一个 Attributes 部分。
  • Sphinx 确实允许您使用文档字符串记录属性。这种情况下的问题是 pebkac,并且有两种不同的语法起作用。

标签: python google-app-engine python-sphinx


【解决方案1】:

答案是 Sphinx 工作得很好。我正在查看尚未重建的文档输出的错误副本。这两种方法都有效:

content = ndb.StringProperty()
"The content"

#: the content
content = ndb.StringProperty()

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2018-11-28
    • 1970-01-01
    • 2013-12-31
    • 2012-12-05
    • 2011-08-22
    • 1970-01-01
    • 1970-01-01
    • 2021-03-08
    相关资源
    最近更新 更多