-
-
Notifications
You must be signed in to change notification settings - Fork 2.1k
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
sphinx.ext: incompatibility between autodoc and viewcode #9395
Comments
@tk0miya do you have any thoughts on this? |
This has other unexpected side effects as well. |
Sorry for the late response. Since 4.0, Sphinx supports "canonical" names for such "import aliased" objects. So |
@tk0miya I'm still seeing a lot of issues, see microsoft/torchgeo#317 for an example of this. Let me know if you aren't able to access https://readthedocs.org/projects/torchgeo/builds/15587403/. Basically, it's a bunch of errors like:
because |
Oops... pytorch has still used Sphinx-3.5.4... To use the "canonical" names via intersphinx, remote project should also use the Sphinx v4.0+. Until then, you should use |
Let me see if I can get PyTorch to update to a newer Sphinx, thanks for the help! |
Describe the bug
Many projects use "import aliases" to simplify their code base. For example, in PyTorch, the
Module
class is defined intorch/nn/modules/modules.py
, but can be imported astorch.nn.Module
. Thetorch/nn/__init__.py
file contains something like:to make this possible. However, this creates two seemingly irreconcilable problems with autodoc and viewcode.
For autodoc, the documentation of these objects appears in
torch.nn
, but when creating links for these classes, autodoc wants to useModule.__module__
, which points totorch.nn.modules.modules
instead. Following the suggestion at https://stackoverflow.com/a/40040000/5828163, this can be "solved" by using:However, this now introduces a problem with viewcode. Viewcode seems to also use the
__module__
attribute to determine where the source code can be found, and links to this. If the__module__
attribute is overridden, now source code links no longer work.Is this a known issue? Is there any workaround for this? I think an ideal scenario would be one where libraries don't have to override
__module__
at all (viewcode now works) and autodoc becomes smart enough to understand that there are multiple possible locations where a class/function could be defined in the documentation. Note that this problem also affects intersphinx for the same reasons as autodoc.To Reproduce
Steps to reproduce the behavior:
conf.py
__module__
to fix thisExpected behavior
I would expect both of these extensions to be compatible in this common situation of import alias usage.
Your project
I'm working on this specifically in the context of PyTorch at pytorch/pytorch#61045 but it affects multiple projects.
Environment info
@ydcjeff @calebrob6
The text was updated successfully, but these errors were encountered: