Skip to content

Use of TypeVar results in "reference target not found" error #10974

@hassec

Description

@hassec

Describe the bug

Simple example below.
The TypeVar seems to get converted into py:data and thus we get an error when the type info in the signature or description tries to link to a py:class for it.

repro.py:docstring of repro.test:: WARNING: py:class reference target not found: repro.T

How to Reproduce

With the below files in a folder, run sphinx-build -Eanb html . build/

index.rst

Repro Warning
=============

.. automodule:: repro
   :members:
   :undoc-members:
   :show-inheritance:

conf.py

import os
import sys
sys.path.insert(0, os.path.abspath('.'))
extensions = ["sphinx.ext.autodoc"]
autodoc_typehints = "both"

repro.py

from typing import TypeVar

T = TypeVar("T")
""" A Generic type """

def test(a: T) -> T:
    """A Test Function"""
    return a

Environment Information

Platform:              linux; (Linux-5.10.16.3-microsoft-standard-WSL2-x86_64-with-glibc2.31) 
Python version:        3.10.7 (main, Sep  6 2022, 21:51:06) [GCC 9.4.0]) 
Python implementation: CPython 
Sphinx version:        5.3.0 
Docutils version:      0.17.1
Jinja2 version:        3.1.2 

Sphinx extensions

autodoc

Additional context

No response

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions