A.Vignon
A.Vignon

Reputation: 375

How to avoid inherited members using autosummary and custom templates?

I generate a python documentation using sphinx.ext.autosummary. The autodoc and autosummary is configured as follow in 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

I use a template :

myModuleName
=======

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

   myModule

Modules template is :

{{ 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 %}

And class template is :

{{ 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 %}

It works fine but this adds every method inherited in the documentation while the flag 'show-inheritance' (which is supposed to add every inherited member) is absent.

Any ideas?

Upvotes: 11

Views: 2641

Answers (1)

eilander17
eilander17

Reputation: 73

it seems indeed that none of the flags (e.g. :no-inherited-members:) have any effect on this, but you could just modify your class template to solve the problem.

{% for item in methods %}
{%- if item not in inherited_members %}
    ~{{ name }}.{{ item }}
{%- endif %}
{%- endfor %}

the above seems to do the trick for me. hope it helps...

Upvotes: 7

Related Questions