Skip to content

Autosummary does not respect autodoc's :meta public: #8922

Closed

Description

@kratsg

Describe the bug

When trying to document private methods (e.g. those prefixed with _) and tell sphinx to treat them as public via :meta public: in the docstring - autodoc shows the method but autosummary does not.

Example python class below:

class Foo:
  def public(self):
    """ I'm public. """
    pass

  def private(self):
    """ I'm private. """
    pass

  def private_public(self):
    """ I'm private, but publicly documented.
    :meta public:
    """
    pass

To Reproduce

.. autoclass:: {{ objname }}
   :show-inheritance:
   :members:

will include the privately documented method correctly, but

.. autoclass:: {{ objname }}
   :show-inheritance:

   {% block methods %}

   {% if methods %}
   .. rubric:: {{ _('Methods') }}

   {% for item in methods %}
   .. automethod:: {{ name }}.{{ item }}
   {%- endfor %}

   {% endif %}
   {% endblock %}

will not. Even more confusingly, autosummary has no functionality to actually document private methods at all (https://www.sphinx-doc.org/en/master/usage/extensions/autosummary.html#customizing-templates) in a trivial way.

Expected behavior

I naively expected autosummary to respect :meta XYZ: that autodoc respects.

Environment info

  • OS: Mac OS Mojave 10.14.6
  • Python version: 3.8.6
  • Sphinx version: 3.5.1
  • Sphinx extensions: [e.g. sphinx.ext.autodoc, recommonmark]
  • Extra tools: [e.g. Browser, tex or something else]

Additional context

A current workaround seems to be to do something like the following instead:

   {% for item in members %}
   {% if item not in attributes and item not in inherited_members and not item.startswith('__') %}
   .. automethod:: {{ name }}.{{ item }}
   {% endif %}
   {%- endfor %}

but this does seem rather lengthy just to be able to get the private methods of a class (and not the special methods/members) by going through all members. Perhaps autosummary needs some extra help.

Activity

  1. tk0miya commented on Feb 23, 2021

    @tk0miya
    Member

    Thank you for reporting.

    Note: this is almost the same as #8700.

  2. kratsg commented on Feb 23, 2021

    @kratsg
    Author

    Note: this is almost the same as #8700.

    Indeed it is! No wonder I couldn't find a related issue as easily. If you want to close this as a duplicate of the other, I would not be opposed -- but I think the bigger issue might be how autosummary generates the variables used for templates (e.g. members, methods, and so on) and that's probably what might need to be looked at (which I touch on a little in this issue).

  3. tk0miya commented on Feb 23, 2021

    @tk0miya
    Member

    The root cause of these issues is the same. autosummary extension does not refer to the metadata at all when listing attributes. Anyway, I'm okay to keep this open. I'll try to fix this when I have time.

  4. added this to the some future version milestone on Sep 29, 2022
  5. jdillard commented on Aug 6, 2026

    @jdillard
    SponsorMember

    Closing in favor of #8700 to consolidate tracking, since both behaviors share the same underlying cause and should be addressed by a single PR.

    The :meta public: behavior reported here is now part of #8700’s combined scope, alongside its complementary :meta private: case.

  6. locked as resolved and limited conversation to collaborators on Sep 4, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Projects

    No projects

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions