Python: document property to specify type

  docstring, numpydoc, python-3.x, python-sphinx

Let’s consider the following example:

class MyClass:
    def __init__(self):
        self._x = None
        
    @property
    def x(self) -> Union[float, np.ndarray]:
        if len(self._x) == 1:
            return self._x[0]
        else:
            return self._x
    
    @x.setter
    def x(self, value: Union[float, list, np.ndarray]):
        self._x = np.atleast_1d(value)

Any suggestion on how can I properly document the above code?
I am using Sphinx and numpydoc.

Thanks a lot!

Source: Python-3x Questions

LEAVE A COMMENT