-
-
Notifications
You must be signed in to change notification settings - Fork 2.2k
automodule fails if path contains an certain names #9479
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Comments
I apologize for raising the wrong issue the first time... I thought I had tracked down the bug but I was mistaken. This is a very easy issue to workaround: just remove the unnecessary mocked import. I just raise this issue because the output seems very strange. When I first encountered this in my code, it properly documented 5/6 classes so I was convinced Sphinx just didn't like the name of one of my classes. |
What do you expect if the mocked object is given? |
I'm not sure I understand the question. I expect that if Sphinx finds the source code from ClassA (which it does, given that the "source" button links to the code) it will be able to document that class. I also expect whatever it does for ClassA, it will do for ClassB---if it fails to document ClassA I think it should fail to document ClassB, but the fact that ClassA fails but ClassB succeeds confuses me. Note that I only encountered this issue because I made a mistake and forgot to remove my package's mock (I'm not suggesting mocking a package in this scenario is a good idea at all). I just thought this caused extremely strange behavior and took me some time to track down why Sphinx was behaving the way it was. |
In my understanding, your case happened from a mistake. So I guess nobody would like to document the mocked object via autodoc and viewcode extensions. Is my guess correct? Or, you really want to document
IMO, it's better to emit a warning if autodoc detects a mocked object. I hope it will help resolving your case. |
Yep, it was my mistake. I can't speak for everyone but I certainly don't actively want to document a mocked object.
That'd be great! |
Fix #9479: autodoc: Emit a warning if target is a mocked object
Describe the bug
If I mock an import using
autodoc_mock_imports
in myconf.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 moduleobservation
that contains classesclassA
andclassB
. Myconf.py
is in a folder on the same level asfoobar
. If I mockfoobar
, the relevant part ofconf.py
looks like the followingMy index.rst file looks like
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'
fromautodoc_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
r/autodoc_issue
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
The text was updated successfully, but these errors were encountered: