如何避免使用自动摘要和自定义模板继承的成员?

A.V*_*non 5 python python-3.x python-sphinx

我使用sphinx.ext.autosummary生成了python文档。autodoc和autosummary在conf.py中配置如下:

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
Run Code Online (Sandbox Code Playgroud)

我使用模板:

myModuleName
=======

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

   myModule
Run Code Online (Sandbox Code Playgroud)

模块模板为:

{{ 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 %}
Run Code Online (Sandbox Code Playgroud)

和类模板是:

{{ 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 %}
Run Code Online (Sandbox Code Playgroud)

它可以正常工作,但是可以添加文档中继承的所有方法,而缺少标志“ show-inheritance”(应该添加所有继承的成员)。

有任何想法吗?

eil*_*r17 7

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

{% for item in methods %}
{%- if item not in inherited_members %}
    ~{{ name }}.{{ item }}
{%- endif %}
{%- endfor %}
Run Code Online (Sandbox Code Playgroud)

以上似乎对我有用。希望能帮助到你...