Repository navigation
Description
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:
"""
passTo 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
tk0miya commentedon Feb 23, 2021
Thank you for reporting.
Note: this is almost the same as #8700.
kratsg commentedon Feb 23, 2021
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
autosummarygenerates 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).tk0miya commentedon Feb 23, 2021
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.
jdillard commentedon Aug 6, 2026
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.