You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
This would fix it for my application, but would break applications that create an attribute with the same name as a builtin, so would probably need a new configuration variable.
Another possible solution would be to get sphinx-autodoc2 to make all TypeVars or unions reftype "class" rather than "data", although that may also be wrong.
I hope you don't mind me tagging you @chrisjsewell but maybe as author of sphinx-autodoc2 you may have an opinion?
How to Reproduce
index
=====
.. py:module:: foo
.. py:data:: T
:value: TypeVar(...)
.. py:class:: Foo(t: T)
I am working around this problem with the following in conf.py:
fromsphinximportaddnodes, application, environmentfromsphinx.extimportintersphinx# A custom handler for TypeVars and Unionsdefmissing_reference_handler(
app: application.Sphinx,
env: environment.BuildEnvironment,
node: addnodes.pending_xref,
contnode,
):
target=node["reftarget"]
if"."intargetandnode["reftype"] =="class":
# Try again as `obj` so we pick up Unions, TypeVars and other thingsiftarget.startswith("ophyd_async"):
# Pick it up from our domaindomain=env.domains[node["refdomain"]]
refdoc=node.get("refdoc")
returndomain.resolve_xref(
env, refdoc, app.builder, "obj", target, node, contnode
)
else:
# pass it to intersphinx with the right typenode["reftype"] ="obj"returnintersphinx.missing_reference(app, env, node, contnode)
defsetup(app: application.Sphinx):
app.connect("missing-reference", missing_reference_handler)
The text was updated successfully, but these errors were encountered:
Describe the bug
This is somewhat related to a number of issues in #11991, but is wider than just autodoc.
It also affects
sphinx-autodoc2
users as TypeVars are created aspy:data
rather thanpy:class
.When creating an xref from an argument annotation, this is called:
sphinx/sphinx/domains/python/_annotations.py
Lines 47 to 53 in 758dc81
This means that if you write code like:
then the python domain expects
T
to be a class, but it is categorized as data:WARNING: py:class reference target not found: foo.T [ref.class]
One possible solution is to widen the reftype in
parse_reftarget
to"obj"
in every case, not just for the typing module:This would fix it for my application, but would break applications that create an attribute with the same name as a builtin, so would probably need a new configuration variable.
Another possible solution would be to get
sphinx-autodoc2
to make all TypeVars or unions reftype "class" rather than "data", although that may also be wrong.I hope you don't mind me tagging you @chrisjsewell but maybe as author of sphinx-autodoc2 you may have an opinion?
How to Reproduce
Environment Information
Sphinx extensions
Additional context
I am working around this problem with the following in conf.py:
The text was updated successfully, but these errors were encountered: