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:

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

   Example.test

becomes:

Example.test(other)

check for equality

Methods on nested accessors can be documented, too:

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

    def func(self, a):
        """namespaced function"""
        print(self._obj, a)


@register_accessor("test2")
class Test2Accessor:
    """ an accessor of Example """

    sub = CachedAccessor("sub", SubAccessor)

    def __init__(self, obj):

and

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

   Example.test2.sub.func

become:

Example.test2.sub.func(a)

namespaced function