斯芬克斯两次显示属性
Sphinx showing attributes twice
我正在尝试使用 sphinx 编写 API 文档
我从模型开始,但无法正确记录属性。
这是一个例子:
class Incoterm(AuditedModel(updatable=True), ModelBase, db.Model):
"""Incoterm Definition
Args:
AuditedModel (class): Audit class
ModelBase (class): Model base class
db (class): SQLAlchemy instance
Attributes:
abbreviation (String): an abbreviation
full_name (String): the full name
group (String): which group it belong
"""
abbreviation = Column(String(3), nullable=False)
full_name = Column(String(128), nullable=False)
group = Column(String(1), nullable=False)
使用 $ sphinx-apidoc -o . ..
和 $ make html
生成的文档显示 属性 两次和 class 没有定义的继承。
我也尝试在 #: str: an string
之类的变量之前插入注释,如 sphinx examples 中所述,但得到了相同的结果...
我发现的一个解决方法是在 .rst 文件中注释 :undoc-members:
。
有更好的方法来实现这一目标吗?我错过了什么?
如果您像这样记录 class 属性,问题可能会消失。
class Incoterm(AuditedModel(updatable=True), ModelBase, db.Model):
"""Incoterm Definition
Args:
AuditedModel (class): Audit class
ModelBase (class): Model base class
db (class): SQLAlchemy instance
"""
abbreviation = Column(String(3), nullable=False)
"""an abbreviation"""
full_name = Column(String(128), nullable=False)
"""the full name"""
group = Column(String(1), nullable=False)
"""which group it belong"""
参考:
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute
向下滚动到 class Foo
示例。
我正在尝试使用 sphinx 编写 API 文档 我从模型开始,但无法正确记录属性。
这是一个例子:
class Incoterm(AuditedModel(updatable=True), ModelBase, db.Model):
"""Incoterm Definition
Args:
AuditedModel (class): Audit class
ModelBase (class): Model base class
db (class): SQLAlchemy instance
Attributes:
abbreviation (String): an abbreviation
full_name (String): the full name
group (String): which group it belong
"""
abbreviation = Column(String(3), nullable=False)
full_name = Column(String(128), nullable=False)
group = Column(String(1), nullable=False)
使用 $ sphinx-apidoc -o . ..
和 $ make html
生成的文档显示 属性 两次和 class 没有定义的继承。
我也尝试在 #: str: an string
之类的变量之前插入注释,如 sphinx examples 中所述,但得到了相同的结果...
我发现的一个解决方法是在 .rst 文件中注释 :undoc-members:
。
有更好的方法来实现这一目标吗?我错过了什么?
如果您像这样记录 class 属性,问题可能会消失。
class Incoterm(AuditedModel(updatable=True), ModelBase, db.Model):
"""Incoterm Definition
Args:
AuditedModel (class): Audit class
ModelBase (class): Model base class
db (class): SQLAlchemy instance
"""
abbreviation = Column(String(3), nullable=False)
"""an abbreviation"""
full_name = Column(String(128), nullable=False)
"""the full name"""
group = Column(String(1), nullable=False)
"""which group it belong"""
参考:
https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html#directive-autoattribute
向下滚动到 class Foo
示例。