Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Move methods into class pages for docs #1290

Merged
merged 10 commits into from
Nov 6, 2023
56 changes: 12 additions & 44 deletions docs/_templates/autosummary/class.rst
Original file line number Diff line number Diff line change
Expand Up @@ -11,59 +11,27 @@
:no-members:
:no-inherited-members:
:no-special-members:
:show-inheritance:
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Why this change? With my original PR, I was too eager in copying over exactly what Qiskit did. You did a better job in your PRs for other repos with making the minimum change necessary to get methods on class pages. It might be possible to get this diff more focused.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thanks @Eric-Arellano! You are right, I was using another template and I let the show-inheritance by error. It's fixed now. This file changes a lot because I removed the counter logic following your PR. Do you think I should add it again? As you can see, in the other templates I made now the minimum changes possible =)


{% block attributes_summary %}
{% block attributes_summary %}
{% if attributes %}

{# This counter lets us only render the heading if there's at least
one valid entry. #}
{% set count = namespace(value=0) %}

{% for item in attributes %}
{% if not item.startswith('_') %}
{% set count.value = count.value + 1 %}
{% if count.value == 1 %}
.. rubric:: Attributes

.. autosummary::
:toctree: ../stubs/
{% endif %}

{{ name }}.{{ item }}
{% endif %}
{% endfor %}
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
.. autoattribute:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}
{% endblock %}

{% block methods_summary %}
{% block methods_summary %}
{% if methods %}

{% set count = namespace(value=0) %}
.. rubric:: Methods
{% for item in all_methods %}

{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{% set count.value = count.value + 1 %}
{% if count.value == 1 %}
.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% endif %}
{{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% for item in inherited_members %}
{%- if item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
{% set count.value = count.value + 1 %}
{% if count.value == 1 %}
.. rubric:: Methods

.. autosummary::
:toctree: ../stubs/
{% endif %}
{{ name }}.{{ item }}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}

{% endif %}
{% endblock %}
{% endblock %}
41 changes: 41 additions & 0 deletions docs/_templates/autosummary/class_no_inherited_members.rst
Original file line number Diff line number Diff line change
@@ -0,0 +1,41 @@
{# This is identical to class.rst, except for the filtering of the inherited_members. -#}

{% if referencefile %}
.. include:: {{ referencefile }}
{% endif %}

{{ objname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
:no-members:
:no-inherited-members:
:no-special-members:
:show-inheritance:

{% block attributes_summary %}
{% if attributes %}
.. rubric:: Attributes
{% for item in all_attributes %}
{%- if not item.startswith('_') %}
.. autoattribute:: {{ name }}.{{ item }}
{%- endif -%}
{%- endfor %}
{% endif %}
{% endblock %}

{% block methods_summary %}
{% if methods %}
.. rubric:: Methods
{% for item in all_methods %}
{%- if item not in inherited_members %}
{%- if not item.startswith('_') or item in ['__call__', '__mul__', '__getitem__', '__len__'] %}
.. automethod:: {{ name }}.{{ item }}
{%- endif -%}
{%- endif -%}
{%- endfor %}

{% endif %}
{% endblock %}