Skip to content

馃悰 fix(parser): stop shadowing intersphinx roles in the rtype probe - #756

Merged
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix-753-nested-sphinx-domains
Aug 24, 2026
Merged

馃悰 fix(parser): stop shadowing intersphinx roles in the rtype probe#756
gaborbernat merged 2 commits into
tox-dev:mainfrom
gaborbernat:fix-753-nested-sphinx-domains

Conversation

@gaborbernat

Copy link
Copy Markdown
Member

A docstring that references another project through an external+... role made the build emit unknown role name: external+demo:doc, as reported in #753. The page rendered fine. Only the warning was wrong, and that was enough to fail any build running Sphinx with -W, with no obvious way to suppress it.

Sphinx enters sphinx_domains once for the whole read phase and sphinx.ext.intersphinx layers IntersphinxDispatcher on top of it, which is what claims role names starting with external+. The throwaway parse that finds where to put :rtype: entered sphinx_domains a second time; CustomReSTDispatcher.enable() overwrites docutils.parsers.rst.roles.role, so the probe replaced the intersphinx layer with a plain domain lookup for its own duration. external+demo matched no domain, and Sphinx warned. That probe runs from autodoc-process-docstring and nowhere else, where the caller has already installed the dispatcher it needs, so this PR drops the nested context manager and lets the outer one stand. 馃攳

The probe still neutralizes non-builtin directives, so extension directives inside docstrings keep running once rather than twice. Roles now behave in the probe as they do in the real parse. A role the outer dispatcher cannot resolve still warns, from the real parse.

Sphinx keeps the intersphinx role dispatcher layered on top of
sphinx_domains for the whole read phase. The throwaway parse that locates
the :rtype: insert point entered sphinx_domains a second time and shadowed
that layer, so an external+ role in a docstring resolved as a domain name
and warned "unknown role name". The rendered output was correct, but builds
that turn warnings into errors failed on docstrings that work fine.

That probe runs inside autodoc-process-docstring, where the dispatcher it
needs is already installed, so the nested context manager only did harm.

Closes tox-dev#753
@gaborbernat
gaborbernat force-pushed the fix-753-nested-sphinx-domains branch from 4544154 to b42e9f2 Compare August 24, 2026 14:38
@gaborbernat
gaborbernat merged commit d98ed0b into tox-dev:main Aug 24, 2026
10 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant