Skip to content

Render undocumented TypeVars as text#14504

Open
gaborbernat wants to merge 2 commits into
sphinx-doc:masterfrom
gaborbernat:fix-restify-typevar
Open

Render undocumented TypeVars as text#14504
gaborbernat wants to merge 2 commits into
sphinx-doc:masterfrom
gaborbernat:fix-restify-typevar

Conversation

@gaborbernat

@gaborbernat gaborbernat commented Jun 26, 2026

Copy link
Copy Markdown
Contributor

Documenting a class that derives from Generic[_T] with show-inheritance failed a nitpicky or -W build whenever _T is private or otherwise undocumented, reporting py:obj reference target not found. restify() links a type variable by its qualified name, and a name with no documentable target leaves a dangling cross-reference, as reported in #14502.

A new missing-reference handler resolves that reference to plain text once it sees the target is a TypeVar or ParamSpec. A documented type variable, or one reachable through intersphinx, still links as before, and the rendering stays the bare name rather than an expanded TypeVar(...) form.

Generic base classes that use an undocumented type variable no longer warn, and documented references keep their links.

AI disclosure: I drafted this description with Claude Code (Anthropic), then reviewed and tested it. The change is mine and I take responsibility for it.

@gaborbernat gaborbernat force-pushed the fix-restify-typevar branch 3 times, most recently from 7c32d9d to fa3d857 Compare June 26, 2026 17:36
@gaborbernat gaborbernat force-pushed the fix-restify-typevar branch from fa3d857 to bcb6c31 Compare June 26, 2026 18:48
@jdillard

Copy link
Copy Markdown
Member

Please update the PR description in accordance with the AI policy: https://www.sphinx-doc.org/en/master/internals/ai-policy.html

@gaborbernat

Copy link
Copy Markdown
Contributor Author

@jdillard Updated the description per the AI policy, with a disclosure line added.

Comment thread sphinx/util/typing.py Outdated

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Documenting TypeVars is, AFAIR, possible with #: or bu explicitly adding an entry for it IIRC. I may be wrong but if this is the case, you must also add tests for autodoc.

I do not think that list[TypeVar(T)] is an acceptable rendering however.

Comment thread tests/test_util/test_util_typing.py Outdated
@gaborbernat gaborbernat requested a review from picnixz June 30, 2026 17:19

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please do not request a review if there is no new code.

@gaborbernat gaborbernat force-pushed the fix-restify-typevar branch from bcb6c31 to dfa0e4e Compare June 30, 2026 21:17
@gaborbernat

Copy link
Copy Markdown
Contributor Author

Reworked per your feedback: dropped the TypeVar(...) expansion. restify now renders just the name, and a missing-reference handler falls back to plain text when the target is an undocumented TypeVar or ParamSpec. Documented ones (and intersphinx) still link. Added tests for the resolver.

@gaborbernat gaborbernat force-pushed the fix-restify-typevar branch from dfa0e4e to 80790f0 Compare June 30, 2026 21:27

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please add E2E tests with autodoc as well (you would likely need toc reate some testdata in testroot)

@gaborbernat gaborbernat changed the title Render TypeVars as text in restify Jun 30, 2026
restify() links a TypeVar by its qualified name. A private or otherwise
undocumented type variable has no documentable target, so a nitpicky or -W
build of a class deriving from Generic[_T] failed with a dangling py:obj
reference.

Add a missing-reference handler that renders the reference as text when its
target resolves to a TypeVar or ParamSpec, leaving documented ones and
intersphinx links untouched.

Fixes sphinx-doc#14502.
@gaborbernat gaborbernat force-pushed the fix-restify-typevar branch from 80790f0 to 259228d Compare June 30, 2026 22:09
@picnixz picnixz changed the title 🐛 fix(py domain): render undocumented TypeVars as text Jun 30, 2026
@picnixz

picnixz commented Jun 30, 2026

Copy link
Copy Markdown
Member

We don't use conventional commit titles in our PRs (and especially not emojis)

@gaborbernat gaborbernat changed the title Render undocumented TypeVars as text Jun 30, 2026

@picnixz picnixz left a comment

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Please don't force push, it's impossible to make incremental reviews.

Comment thread tests/roots/test-ext-autodoc/target/private_typevar.py Outdated
Cover documented and undocumented type variables across bases, methods,
and a module-level function, plus covariant, bound, constrained, and
ParamSpec cases. A documented one links; an undocumented one renders as
text. Follows up on review feedback for sphinx-doc#14504.
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

3 participants