sphinx icon indicating copy to clipboard operation
sphinx copied to clipboard

References to inherited Python methods do not produce a link

Open andy-maier opened this issue 3 years ago • 0 comments

Describe the bug

Consider the following Python module:

File mymodule/__init__.py:

"""
Module mymodule.

* Reference to method Base.meth_base: :meth:`mymodule.Base.meth_base`.
* Reference to inherited method A.meth_base: :meth:`mymodule.A.meth_base`. - does not produce a link
* Reference to method A.meth_a: :meth:`mymodule.A.meth_a`.
"""

__version__ = '0.1.0'

class Base(object):
    """
    Class Base.
    """

    def meth_base(self):
        """
        Method meth_base().
        """

class A(Base):
    """
    Class A derived from class Base.
    """

    def meth_a(self):
        """
        Method meth_a.
        """

The reference to the inherited Python method mymodule.A.meth_base does not produce a link.

This goes along with a warning issued by Sphinx:

/Users/.../mymodule/__init__.py:docstring of mymodule:4: WARNING: py:meth reference target not found: mymodule.A.meth_base

How to Reproduce

# Create a fresh Python virtual environment with Python 3.6 or higher
# Download and extract the attached sphinx_inherited_links.zip file
$ cd sphinx_inherited_links
$ pip install -r requirements.txt
$ sphinx-build -b html -v -n -d build_doc/doctrees -c docs docs build_doc/html
$ open build_doc/html/index.html and look at the reference to the inherited method A.meth_base

Expected behavior

References to inherited methods should create a link, if the target has a docstring in the same Sphinx output document.

Your project

sphinx_inherited_links.zip

Screenshots

No response

OS

macOs

Python version

3.9

Sphinx version

5.0.2

Sphinx extensions

sphinx.ext.autodoc, sphinx.ext.napoleon

Extra tools

No response

Additional context

This may be related to issues #9290 or #4600 or to the rather old requirement #272.

I originally encountered this issue in context of autodocsumm, see https://github.com/Chilipp/autodocsumm/issues/50, but meanwhile reduced the problem to plain Sphinx references in a much reduced Sphinx environment.

andy-maier avatar Jul 24 '22 11:07 andy-maier