馃悰 fix(parser): stop shadowing intersphinx roles in the rtype probe - #756
Merged
gaborbernat merged 2 commits intoAug 24, 2026
Merged
Conversation
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
force-pushed
the
fix-753-nested-sphinx-domains
branch
from
August 24, 2026 14:38
4544154 to
b42e9f2
Compare
for more information, see https://pre-commit.ci
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
A docstring that references another project through an
external+...role made the build emitunknown 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_domainsonce for the whole read phase andsphinx.ext.intersphinxlayersIntersphinxDispatcheron top of it, which is what claims role names starting withexternal+. The throwaway parse that finds where to put:rtype:enteredsphinx_domainsa second time;CustomReSTDispatcher.enable()overwritesdocutils.parsers.rst.roles.role, so the probe replaced the intersphinx layer with a plain domain lookup for its own duration.external+demomatched no domain, and Sphinx warned. That probe runs fromautodoc-process-docstringand 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.