Examples

Consider the accessor class:



@register_accessor("test")
class TestAccessor:
    """ an accessor of Example """

    def __init__(self, obj):
        self._obj = obj

    def __call__(self, other):
        """ check for equality

        Parameters
        ----------
        other
            The value to compare to

        Returns
        -------
        result : bool
        """

        return self._obj._data == other

    @property
    def double(self):
        """ double the data """
        return self.multiply(2)

    def multiply(self, factor):
        """ multiply data with a factor

        Parameters
        ----------
        factor : int
            The factor for the multiplication
        """

        return self._obj._data * factor

for a class named Example:

Example(data)

test class

Documenting attributes and methods can be done with the accessor_attribute.rst and accessor_method.rst templates:

.. autosummary::
   :toctree: generated/
   :template: autosummary/accessor_attribute.rst

   Example.test.double

.. autosummary::
   :toctree: generated/
   :template: autosummary/accessor_method.rst

   Example.test.multiply

becomes:

Example.test.double

double the data

Example.test.multiply(factor)

multiply data with a factor

Callable accessors can be documented, too:

Warning

This feature is only fully supported from sphinx version 3.1 onwards. On earlier versions, the summary will claim this is a alias of the accessor class.

.. autosummary::
   :toctree: generated/
   :template: autosummary/accessor_callable.rst

   Example.test

becomes:

Example.test(other)

check for equality