Skip to content

intersphinx: fall back to py:data / py:attribute for py:class references - #14730

Open
bhaskargurram-ai wants to merge 1 commit into
sphinx-doc:masterfrom
bhaskargurram-ai:fix/intersphinx-class-role-fallback
Open

bhaskargurram-ai wants to merge 1 commit into
sphinx-doc:masterfrom
bhaskargurram-ai:fix/intersphinx-class-role-fallback

Conversation

@bhaskargurram-ai

Copy link
Copy Markdown

Purpose

Type annotations can generate py:class references for TypeVars and type aliases, even when other projects document them as py:data or py:attribute. Intersphinx cannot resolve these references when the expected py:class target does not exist, which results in "reference target not found" warnings. Projects such as SymPy, BayBE and khisto-python have added workarounds for this.

Sphinx 9.0 already addressed this for local references in #13808, by falling back from py:class to py:data and then py:attribute. Intersphinx does not use the same fallback yet.

This PR updates intersphinx to try py:data and then py:attribute when a py:class lookup fails.

What doesn't change:

  • Actual classes with the same name keep priority.
  • Methods are not matched, consistent with local reference resolution.
  • Other roles and domains are unaffected.

Tests: a regression test that fails without the change and passes with it; the existing intersphinx and domain tests continue to pass.

Also adds an entry to CHANGES.rst and my name to AUTHORS.rst.

References

AI Disclosure

I used Claude Code to search for existing work, draft the code change in sphinx/ext/intersphinx/_resolve.py.

Type aliases and type variables are documented as py:data or
py:attribute, but references generated from annotations use the
py:class role. The Python domain already falls back from 'class' to
'data' and then 'attr' when resolving such references locally, but
intersphinx only searched the object types of the 'class' role.

Apply the same ordered fallback when resolving a py:class reference
against an inventory, without the legacy py:method alias that the
'attr' role adds for old property entries.

This branch has not been deployed

No deployments
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

Successfully merging this pull request may close these issues.

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

1 participant