Skip to content

imported-members and show-inheritance leads to broken links #546

@rihands

Description

@rihands

In short, the issue is that show-inheritance defaults to not fully qualifying the name of any base classes that are in the same file as the derived class, while imported-members just copies the documentation of imported members wholesale. As a result, if an __init__.py imports a derived class but not a base class, the reference target will not be found for the base class in the __init__.py's documentation.

#411 would fix this, but this is a separate issue.

Alternatively, having show-inheritance always fully qualify the names of base classes (possibly using a ~ prefix for classes in the same file) would also fix this.

Minimal reproduction

src/testproject/__init__.py:

"""It's a module."""

from testproject.classes import MySubclass


__all__ = ["MySubclass"]

src/testproject/classes.py

"""Some classes."""


class MyBase:
    """A base class."""


class MySubclass(MyBase):
    """A subclass."""

docs/src/conf.py

from pathlib import Path


PROJECT_ROOT = Path(__file__).parents[2]


extensions = [
    "autoapi.extension",
]

autoapi_dirs = [(PROJECT_ROOT / "src" / "testproject").as_posix()]

autoapi_options = [
    "imported-members",
    "show-inheritance",
]

docs/src/index.rst

.. toctree::

Run uv run --isolated --with sphinx --with sphinx-autoapi -m sphinx -b html --nitpicky docs/src docs/build; see the warning [...]\docs\src\autoapi\testproject\index.rst:28: WARNING: py:obj reference target not found: MyBase [ref.obj].

Note that the generated documentation for MySubclass is

.. py:class:: MySubclass

   Bases: :py:obj:`MyBase`


   A subclass.

This should probably use :py:obj:`~testproject.classes.MyBase` instead.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions