Prevent the sphinx from following inherited doctrines

We created a library that uses the massive (with inheritance) numpy MaskedArrays. But I want to run sphinx make doctestwithout testing the inherited methods from numpy, because they make about 100 crashes.

It looks like this:

class _frommethod:
    """
    Adapted from numpy.ma._frommethod
    """

    def __init__(self, func_name):
        self.__name__ = func_name
        self.__doc__ = getattr(MaskedArray, func_name).__doc__
        self.obj = None

    def __get__(self, obj, objtype=None):
        self.obj = obj
        return self

    def __call__(self, a, *args, **params):
        # Get the method from the array (if possible)
        method_name = self.__name__
        method = getattr(a, method_name, None)
        if method is not None:
            return method(*args, **params)
        # Still here ? Then a is not a MaskedArray
        method = getattr(MaskedTimeData, method_name, None)
        if method is not None:
            return method(MaskedTimeData(a), *args, **params)
        # Still here ? OK, let call the corresponding np function
        method = getattr(np, method_name)

And now that our library also supports numpy functions, we use:

min = _frommethod('min')
max = _frommethod('max')
...

If disabled self.__doc__ = getattr(MaskedArray, func_name).__doc__, the failure make doctestwill disappear. But I would like to keep the legacy documentation; so users can still use mylibrary.min?in ipython.

Does anyone know how I can prevent the sphinx from following these โ€œinheritedโ€ doctrines?

+5
source share
1 answer

I am using this solution now:

def _dont_doctest_inherited_docstrings(docstring):
    docstring_disabled = ""
    for line in docstring.splitlines():
        docstring_disabled += line + "#doctest: +DISABLE"
    return docstring_disabled

class _frommethod:
    """
    Adapted from numpy.ma._frommethod
    """

    def __init__(self, func_name):
        self.__name__ = func_name
        docstring = getattr(MaskedArray, func_name).__doc__
        self.__doc__ = _dont_doctest_inherited_docstrings(docstring)
        self.obj = None

Maybe someone has a smarter way!

+2
source

All Articles