Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

autodoc a class that extends a mocked class

I'm trying to run autodoc over a class that extends an external class.

I've used mock so that the import is accepted.

For that I used what was described in this blog http://blog.rtwilson.com/how-to-make-your-sphinx-documentation-compile-with-readthedocs-when-youre-using-numpy-and-scipy/

import mock

MOCK_MODULES = ['de', 'de.xyz', 'de.xyz.class_that_is_extended']
for mod_name in MOCK_MODULES:
  sys.modules[mod_name] = mock.Mock()

The python file I try to document looks like this: from de.xyz import class_that_is_extended

class extending_class (class_that_is_extended):
'''
  docstring
'''

After running sphinx the result is, that just the class name plus the link to the source is shown.

When I change the line "class extending_class (class_that_is_extended):" to "class extending_class (object):" sphinx/autodoc generates the documentation with docstring.

How can I leave the class as is and still get the docstring in the documentation?

like image 611
whoWho Avatar asked Oct 31 '22 17:10

whoWho


1 Answers

Using the apporach posted here: Sphinx-doc :automodule: with Mock imports

I just changed this line:

sys.modules[mod_name] = mock.Mock()

to:

sys.modules[mod_name] = mock.Mock(class_that_is_extended=object)

and removed 'de.xyz.class_that_is_extended' from MOCK_MODULES

like image 200
whoWho Avatar answered Nov 11 '22 17:11

whoWho