Skip to content
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

Intersphinx looks for implementation modules #178

Closed
crusaderky opened this issue Jul 23, 2020 · 2 comments
Closed

Intersphinx looks for implementation modules #178

crusaderky opened this issue Jul 23, 2020 · 2 comments
Milestone

Comments

@crusaderky
Copy link

In my project I have:
mymod.py:

class MyCache(cachetools.LRUCache): ...

mymod.rst:

.. autoclass:: mymod.MyCache
   :members:
   :undoc-members:
   :show-inheritance:

sphinx-build -W fails with:

mymod.py:docstring of mymod.MyCache:1: WARNING: 
py:class reference target not found: cachetools.lru.LRUCache

The problem is that, in objects.inv, the object appears (correctly) under its public module, but LRUCache.__module__ points to the implementation module:

$ python -m sphinx.ext.intersphinx https://cachetools.readthedocs.io/en/latest/objects.inv| grep LRUCache
        cachetools.LRUCache                      index.html#cachetools.LRUCache

Workaround

In conf.py:

import cachetools
cachetools.LRUCache.__module__ = "cachetools"

Solution

The __module__ hack above should be in cachetools.__init__.

External references

This issue is very common. Here's the exact same problem in two other projects:

@crusaderky
Copy link
Author

Starting from Sphinx 3, this extends to anything that declares LRUCache in a type annotation.

@crusaderky crusaderky changed the title Intersphinx :show-inheritance: looks for implementation modules Intersphinx looks for implementation modules Jul 28, 2020
@tkem
Copy link
Owner

tkem commented Jul 29, 2020

@crusaderky: Good point, and thanks for your efforts analyzing this!
I already thought about "flattening" this module, i.e. putting all the cache classes and decorators of the cachetools modules in a single file, as is usually done by the Python standard library. However, this also has some drawbacks ;-)
Your "workaround" sounds somewhat reasonable, but I'll keep watching how other packages decide to handle this for a while.

@tkem tkem added this to the 4.2.0 milestone Sep 8, 2020
@tkem tkem removed this from the 4.2.0 milestone Dec 9, 2020
@tkem tkem added this to the v4.2.3 milestone Sep 26, 2021
@tkem tkem closed this as completed in be507a6 Sep 29, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

No branches or pull requests

2 participants