pythonnumpydocstringnumpydoc

numpydoc conventions: method modifies class but returns nothing


Question about numpydoc docstring conventions:

I have a class that contains a number of methods that return nothing, but add an attribute to the class. For example:

class MyClass(object):
    def __init__(self, a, b):
         self.a = a
         self.b = b
         return

    def a_mult(self, mult):
        """
        Multiplies `a` by `mult`.

        Parameters
        ----------
        mult : float
            Value to multiply `a` by.

        Returns
        -------
        None
        """
        self.product = a * mult
        return

In this clumsy example, MyClass.a_mult doesn't return anything, but adds an attribute to MyClass.

I've included a docstring for MyClass.a_mult following the numpydoc style guide. The docstring states that the method returns None, but I can't see a standard way of documenting how the MyClass.a_mult method modifies the MyClass instance.

Thanks in advance for your help!


Solution

  • Following the helpful suggestions of @mgilson and @user2357112, I realised my classes were poorly designed. I have altered the so all stages of data analysis are stored in a dict. Analysis functions now add elements to the dict, rather than adding new attributes to the class instance.

    Thanks for the pointers.