sphinx-doc / sphinx

The Sphinx documentation generator
https://www.sphinx-doc.org/
Other
6.46k stars 2.1k forks source link

References to TypeVars are not resolved when using autodoc_typehints = "description" #9172

Open hoefling opened 3 years ago

hoefling commented 3 years ago

Describe the bug This is the follow-up of #7119. When using autodoc_typehints = "description" in conf.py, the references to TypeVars are not resolved.

Your project demo.zip

To Reproduce Steps to reproduce the behavior:

$ # download demo.zip
$ unzip demo.zip
$ pip install "sphinx==4.0.0b2"
$ sphinx-build -EWanb html doc/ build/
Running Sphinx v4.0.0b2
building [mo]: all of 0 po files
building [html]: all source files
updating environment: [new config] 1 added, 0 changed, 0 removed
reading sources... [100%] index                                                                                                                                                               
looking for now-outdated files... none found
pickling environment... done
checking consistency... done
preparing documents... done
writing output... [100%] index                                                                                                                                                                

Warning, treated as error:
/tmp/demo/x.py:docstring of x.Container.put::py:class reference target not found: x.T

Expected behavior The rendered parameter type in element (x.T) – should be referencing x.T. Please note that when autodoc_typehints = "description" is turned off (or set back to "signature"), the refs are present so the fix for #7119 works nicely; this is only not the case for "description".

Screenshots

autodoc_typehints = "description":

image

autodoc_typehints = "signature":

image

Environment info

Additional context Add any other context about the problem here.

hoefling commented 3 years ago

I have looked a bit up myself, the difference between the node in both modes is that in description mode, it has node["refspecific"] = True set in PyXrefMixin.make_xref(). Thus, when the reference is resolved in ReferencesResolver.run, the searchmode in PythonDomain.resolve_xref is 1 (vs 0 in signature case). Hope this may be of any help!