2

I would like to document the metaclass members of a class because those are basically class methods and class attributes.

Here's a minimal example:

"""Module docstring

.. autosummary:
   :toctree: _autosummary

   Foo

"""

class MetaFoo(type):
    """Foo metaclass"""


    def foo(cls):
        """Foo class method"""
        return "foo"


    @property
    def x(cls):
        """x class property"""
        return 42


class Foo(metaclass=MetaFoo):
    """Foo class"""


    def bar(self):
        """Bar method"""
        return "bar"

I'm using autosummary, so I tried the following as my _templates/autosummary/class.rst:

{{ objname }}
{{ underline }}

.. currentmodule:: {{ module }}

.. autoclass:: {{ objname }}
   :members:
   :special-members:
   :inherited-members:
   :undoc-members:

But neither the class method nor the class attribute are in the resulting documentation. How can I add the members of the metaclass? I haven't been able to figure out how to access the metaclass in the template. None of the template variables seem helpful to me. Can I perhaps pass the metaclass or its members as custom variables to the template somehow? For instance, if I had metaclass_methods and metaclass_attributes template variables, I could loop over those in the class.rst template. But how can I create and pass these to the template?

mzjn
  • 48,958
  • 13
  • 128
  • 248
Jaakko Luttinen
  • 695
  • 2
  • 7
  • 21

0 Answers0