首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >如何避免继承的成员使用自动汇总和自定义模板?

如何避免继承的成员使用自动汇总和自定义模板?
EN

Stack Overflow用户
提问于 2017-05-15 23:48:40
回答 1查看 1.4K关注 0票数 8

我使用sphinx.ext.autosummary生成python文档。在conf.py中,autodocautosummary的配置如下:

代码语言:javascript
复制
autodoc_member_order = 'bysource'
## Default flags used by autodoc directives
autodoc_default_flags = ['members','undoc-members']
## Generate autodoc stubs with summaries from code
autosummary_generate = True

我使用一个模板:

代码语言:javascript
复制
myModuleName
=======

.. autosummary::
   :toctree: _autosummary
   :template: modules.rst

   myModule

模块模板为:

代码语言:javascript
复制
{{ fullname }}
{{ underline }}

.. automodule:: {{ fullname }}

   {% block functions %}
   {% if functions %}
   .. rubric:: Functions

   .. autosummary::
      :toctree: {{ objname }}
   {% for item in functions %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block classes %}
   {% if classes %}
   .. rubric:: Classes

   .. autosummary::
      :toctree: {{ objname }}
      :template: class.rst
   {% for item in classes %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block exceptions %}
   {% if exceptions %}
   .. rubric:: Exceptions

   .. autosummary::
   {% for item in exceptions %}
      {{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

类模板为:

代码语言:javascript
复制
{{ fullname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}

   {% block methods %}

   {% if methods %}
   .. rubric:: Methods

   .. autosummary::
      :toctree: {{ objname }}
   {% for item in methods %}
      ~{{ name }}.{{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

   {% block attributes %}
   {% if attributes %}
   .. rubric:: Attributes

   .. autosummary::
      :toctree: {{ objname }}
   {% for item in attributes %}
      ~{{ name }}.{{ item }}
   {%- endfor %}
   {% endif %}
   {% endblock %}

它工作得很好,但它添加了文档中继承的每个方法,而没有'show-inheritance‘标志(它应该添加每个继承的成员)。

有什么想法吗?

EN

回答 1

Stack Overflow用户

发布于 2019-01-11 19:09:01

看起来确实没有任何标志(例如:no-inherited-members:)对此有任何影响,但是你可以修改你的类模板来解决这个问题。

代码语言:javascript
复制
{% for item in methods %}
{%- if item not in inherited_members %}
    ~{{ name }}.{{ item }}
{%- endif %}
{%- endfor %}

上面的内容似乎对我很有帮助。希望这能帮上忙。

票数 4
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/43983799

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档