Skip to content

Commit 8e34d91

Browse files
pvcravenPaul V Cravenclaude
authored
Link type in docs signatures to Python's type (#2971)
When an annotation names a class Sphinx can't find, it falls back to attributes whose names end with it, so type[W] linked to arcade.types.TiledObject.type. A Python domain subclass skips arcade's objects for type in signatures, so intersphinx links Python's. Co-authored-by: Paul V Craven <paul.craven@optimizley.com> Co-authored-by: Claude Opus 5.5 <noreply@anthropic.com>
1 parent 7e2fcff commit 8e34d91

1 file changed

Lines changed: 17 additions & 0 deletions

File tree

‎doc/conf.py‎

Lines changed: 17 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,7 @@
1111
import sys
1212

1313
from docutils import nodes
14+
from sphinx.domains.python import PythonDomain
1415
from sphinx.util.docutils import SphinxRole
1516

1617
HERE = Path(__file__).resolve()
@@ -510,6 +511,21 @@ def _get_dir(app, path):
510511
generate_color_table(_get_dir(_app, "uicolor.py"), source)
511512

512513

514+
class ArcadePythonDomain(PythonDomain):
515+
"""Sphinx's Python domain, except ``type`` in a signature links to Python's.
516+
517+
When an annotation names a class Sphinx can't find, it falls back to
518+
attributes with any name ending in that name, so ``type[W]`` linked to
519+
:py:attr:`arcade.types.TiledObject.type`. Returning ``None`` lets
520+
intersphinx link Python's ``type`` instead.
521+
"""
522+
523+
def resolve_xref(self, env, fromdocname, builder, typ, target, node, contnode):
524+
if target == "type" and node.hasattr("refspecific"):
525+
return None
526+
return super().resolve_xref(env, fromdocname, builder, typ, target, node, contnode)
527+
528+
513529
def on_missing_reference(app, env, node, contnode):
514530
"""Link a short name from SHORT_NAMES to its full name."""
515531
full_name = SHORT_NAMES.get(node.get("reftarget"))
@@ -585,6 +601,7 @@ def setup(app):
585601
app.connect("autodoc-process-bases", on_autodoc_process_bases)
586602
# Run before intersphinx, so it can resolve the full names of pyglet objects
587603
app.connect("missing-reference", on_missing_reference, priority=400)
604+
app.add_domain(ArcadePythonDomain, override=True)
588605
# app.add_transform(Transform)
589606
app.add_role("resource", ResourceRole())
590607
# Don't do anything that can fail on this event or it'll kill your build hard

0 commit comments

Comments
 (0)