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

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

Open
hassec opened this issue Nov 15, 2022 · 2 comments
Open

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

hassec opened this issue Nov 15, 2022 · 2 comments

Comments

@hassec
Copy link
Contributor

hassec commented Nov 15, 2022

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

@hassec
Copy link
Contributor Author

hassec commented Nov 15, 2022

I think this is actually the same problem that is reported in #10785.

And more generally it seems that using something as a type hint that isn't documented as py:class: will always result in this error.
This is also true for numpy.float64 which for example is documented as :py:attr: so intersphinx+type hinting leads to the same error.

@AA-Turner AA-Turner added this to the some future version milestone Apr 29, 2023
AVHopp added a commit to emdgroup/baybe that referenced this issue Dec 18, 2023
This PR fixes the following minor errors and aspects in the documentation.
1. The `Smiles` type alias introduced in `parameters.substance`. This
type alias is manually configured in `conf.py`. In order to avoid the
documentation to load all of the attributes and functions of `str`, the
templates were changed slightly to not include those, resulting in the
output shown at the end.
2. The generics in `baybe.utils.basic`. Sphinx behaves weird when using
generics (see sphinx-doc/sphinx#10974). Thus,
an exception was included in the nitpick_ignore dictionary, eliminating
the error.
3. The order of the examples in the table of contents as well as the level of
displayed headings was adjusted
jkoelndorfer added a commit to jkoelndorfer/d2lfg that referenced this issue Jan 7, 2024
Sphinx does not seem to resolve these correctly and with nitpick
mode on, Sphinx will produce an error.

See sphinx-doc/sphinx#10974.
jkoelndorfer added a commit to jkoelndorfer/d2lfg that referenced this issue Jan 7, 2024
Sphinx does not seem to resolve these correctly and with nitpick
mode on, Sphinx will produce an error.

See sphinx-doc/sphinx#10974.
@jakkdl
Copy link

jakkdl commented Aug 25, 2024

I think this is actually the same problem that is reported in #10785.

And more generally it seems that using something as a type hint that isn't documented as py:class: will always result in this error. This is also true for numpy.float64 which for example is documented as :py:attr: so intersphinx+type hinting leads to the same error.

I am also hitting this with annotations using e.g. math.inf and types.FrameType which are set to :py:data:. There appears to be lots of objects in the standard library that are not possible to reference (w/o a workaround) for this reason.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

3 participants