🐛 fix(toctree): crash with empty title in toctree#296
Merged
gaborbernat merged 1 commit intotox-dev:mainfrom Mar 16, 2026
Merged
🐛 fix(toctree): crash with empty title in toctree#296gaborbernat merged 1 commit intotox-dev:mainfrom
gaborbernat merged 1 commit intotox-dev:mainfrom
Conversation
Sphinx's TocTreeCollector expects all section nodes to have a title
child. When :title: was empty, the section("") node had no title child,
causing "list index out of range" when the page was included in a
toctree (e.g. pyproject-fmt's docs).
Using container instead of section avoids the toctree collector
entirely since containers don't participate in document sectioning.
047f03b to
b131c6d
Compare
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.
When a page using
:title:(empty) is included in a toctree, Sphinx'sTocTreeCollector.process_doccrashes withlist index out of range. This breaks documentation builds for projects like pyproject-fmt that place the CLI directive on a separate page referenced from a toctree.The previous fix (2e8609c) changed
paragraph()tosection(""), but asectionnode without a title child still triggers the crash because the toctree collector expects all sections to have a title as their first child. Usingcontainer("")instead avoids this entirely — containers are generic block-level grouping elements that don't participate in document sectioning, so the toctree collector simply ignores them.The test now mirrors the real-world scenario: the directive lives on a separate
cli.rstpage that is included via.. toctree::fromindex.rst, which is the exact structure that triggers the bug.