-
-
Notifications
You must be signed in to change notification settings - Fork 2.3k
Description
Describe the bug
If I mock an import using autodoc_mock_imports in my conf.py and a mocked import is a package I try to document using automodule, it will fail to document anything. Some classes documented in this way using autoclass will say the class in question is an alias of its module; other times it will work correctly. From my brief tests, autofunction works correctly.
How to Reproduce
Suppose I have a package named foobar containing module observation that contains classes classA and classB. My conf.py is in a folder on the same level as foobar. If I mock foobar, the relevant part of conf.py looks like the following
import os
import sys
sys.path.insert(0, os.path.abspath('../'))
extensions = [
'sphinx.ext.autodoc',
'sphinx.ext.napoleon',
'sphinx.ext.viewcode'
]
autodoc_mock_imports = ['foobar']
My index.rst file looks like
.. automodule:: foobar.observation
.. autoclass:: foobar.observation.classA
:members:
.. autoclass:: foobar.observation.classB
:members:
When I generate documentation, it will display nothing from the automodule directive. It will display alias of foobar.observation. as the output to classA. It will correctly display classB. Curiously enough, the "source" button in the output documentation still links to the code, suggesting Sphinx is finding classA but just not documenting it.
If I simply remove 'foobar' from autodoc_mock_imports then this issue vanishes. See the attached screenshots for rendered output where I include my package name in the mocked imports, and a screenshot of the same code with that string removed from the mocked imports.
Expected behavior
I expect the two cases described above to return the same output.
Your project
https://github.com/kconnour/autodoc_issue
Screenshots
OS
Ubuntu 20.10
Python version
3.9
Sphinx version
4.1.1
Sphinx extensions
sphinx.ext.autodoc, sphinx.ext.napoleon, sphinx.ext.viewcode
Extra tools
No response
Additional context
No response

