2

I'm documenting some Python code that has multiple layers of inheritance using Sphinx. The structure is roughly:

class _foo(np.ndarray):
    #do _foo stuff

class bar(_foo):
    #do bar stuff

class baz(_foo):
    #do baz stuff

With :inherited-members: in my .rst file I get the documentation from _foo as part of bar and baz but I also get all the documentation from np.ndarray, which I don't want.

The Sphinx documentation (https://www.sphinx-doc.org/en/master/usage/extensions/autodoc.html) says:

For example; If your class Foo is derived from list class and you don’t want to document list.__len__(), you should specify a option :inherited-members: list to avoid special members of list class.

But I've tried:

  • :inherited-members: np.ndarray
  • :inherited-members: ndarray
  • :inherited-members: numpy.ndarray

None of which prevent the entirety of numpy.ndarray documentation being included for every single class. Does anyone know if there's a way to exclude the numpy documentation, but keep the parts I need? Thanks.

defladamouse
  • 567
  • 2
  • 13
  • 3
    Note that this feature is new in Sphinx 3.0 so... you need Sphinx 3.0 in order to filter `:inherited-members:` by superclass. Also provide a working reproduction case, because I can't even get sphinx 3 to add `np.ndarray`'s documentation to `bar` in a local project. – Masklinn May 08 '20 at 08:49

1 Answers1

1

As explained in comments by @Masklinn, requires version 3.0 or higher, it then works correctly with:

:inherited-members: ndarray
Steve Piercy
  • 13,693
  • 1
  • 44
  • 57
defladamouse
  • 567
  • 2
  • 13