Skip to content

Alias type warning when declare in function param or return type #542

@jgraulle

Description

@jgraulle

I have understood from #414 the alias type are supported from sphinx-autoapi 3.6.0.

When I tried to use an alias type as a param or a return type, when a build the documentation I get the message WARNING: py:class reference target not found: MyAlias[ref.class]. I have tried with the sphinx-autoapi 3.6.0 and 3.6.1 version.

Maybe is not a sphinx-autoapi issue but more low level, and maybe I have made a mistake when configure my project.

I have:

  • requirements.txt
Sphinx==8.2.3
sphinx-autoapi==3.6.1
  • docs/conf.py
project = 'sphinx_test'
copyright = 'None'
author = 'None'
extensions = ['autoapi.extension']
autoapi_type = 'python'
autoapi_dirs = ['../src']
autoapi_keep_files = True
  • docs/index.rst
.. toctree::
   :maxdepth: 1

   autoapi/index

  • src/module.py
"""A module"""

import typing


class MyClass:
    """A class"""
    pass

MyAliasAsSimpleVariableAssignments = str | int
"""An alias with simple variable assignments"""

MyAliasAsTypeAlias: typing.TypeAlias = float | None
"""An alias with TypeAlias"""

type MyAliasAsType = str | int
"""An alias with type"""

MyAliasAsTypeVar = typing.TypeVar("MyAliasAsTypeVar", bool, bytes)
"""An alias with type var"""

def functionClass(param: MyClass) -> MyClass:
    """
    - :py:class:`MyClass` is OK
    - :py:type:`MyClass` is OK
    - Param and return function link are OK
    """
    return MyClass()

def functionAliasAsSimpleVariableAssignments(param: MyAliasAsSimpleVariableAssignments) \
        -> MyAliasAsSimpleVariableAssignments:
    """
    - :py:class:`MyAliasAsSimpleVariableAssignments` is OK
    - :py:type:`MyAliasAsSimpleVariableAssignments` is OK
    - Param and return function link are KO
    """
    return "TODO"

def functionAliasAsTypeAlias(param: MyAliasAsTypeAlias) -> MyAliasAsTypeAlias:
    """
    - :py:class:`MyAliasAsTypeAlias` is OK
    - :py:type:`MyAliasAsTypeAlias` is OK
    - Param and return function link are KO
    """
    return "TODO"

def functionAliasAsType(param: MyAliasAsType) -> MyAliasAsType:
    """
    - :py:class:`MyAliasAsType` is OK
    - :py:type:`MyAliasAsType` is OK
    - Param and return function link are KO
    """
    return "TODO"

def functionAliasAsTypeVar(param: MyAliasAsTypeVar) -> MyAliasAsTypeVar:
    """
    - :py:class:`MyAliasAsTypeVar` is OK
    - :py:type:`MyAliasAsTypeVar` is OK
    - Param and return function link are KO
    """
    return "TODO"

When I run sphinx-build -M html docs build --nitpicky I get some warnings:

.../docs/autoapi/module/index.rst:34: WARNING: py:class reference target not found: MyAliasAsSimpleVariableAssignments [ref.class]
.../docs/autoapi/module/index.rst:41: WARNING: py:class reference target not found: MyAliasAsTypeAlias [ref.class]
.../docs/autoapi/module/index.rst:48: WARNING: py:class reference target not found: MyAliasAsType [ref.class]
.../docs/autoapi/module/index.rst:55: WARNING: py:class reference target not found: MyAliasAsTypeVar [ref.class]

And in the generated HTML documentation some links are ok and some ok (see comment in src/module.py)

I have tried some workaround like several ways to declare a alias, use from __future__ import annotations with autodoc_type_aliases, but I did not managed to make it work.

Is it a problem with my workspace ? Is it a new issue ?

The full zip of this example pythonSphinxAlias.zip

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