斯芬克斯显示属性两次

2024-09-30 08:16:00 发布

您现在位置:Python中文网/ 问答频道 /正文

我正在尝试使用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生成的文档两次显示属性,并在没有定义的情况下显示类继承

我还尝试在变量#: str: an string前面插入注释,如sphinx examples中所述,但得到了相同的结果

我发现的一个解决方法是.rst文件中的注释:undoc-members:。 有更好的方法来实现这一点吗?我错过了什么

enter image description here


Tags: name文档falsestring属性sphinxgroupcolumn
1条回答
网友
1楼 · 发布于 2024-09-30 08:16:00

如果像这样记录类属性,问题很可能会消失

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示例

相关问题 更多 >

    热门问题