Fix IndexError when a module docstring contains only a heading

pull/423/head
Ashley Whetter 3 months ago
parent 422004ea91
commit c4db7eb14a

@ -58,9 +58,10 @@ class NestedParse(Directive):
node.document = self.state.document
nested_parse_with_titles(self.state, self.content, node)
try:
title_node = node[0][0]
if isinstance(title_node, nodes.title):
del node[0][0]
if isinstance(node[0], nodes.section) and isinstance(
node[0][0], nodes.title
):
node.children = node[0][1:] + node.children[1:]
except IndexError:
pass
return node.children

@ -0,0 +1 @@
Fix IndexError when a module docstring contains only a heading

@ -1,3 +1,8 @@
"""
This heading will be removed
============================
"""
from .subpackage import public_chain
from .subpackage.submodule import public_multiple_imports

@ -1,3 +1,11 @@
"""
This heading will be removed
============================
This docstring will not be removed.
"""
def public_chain():
"""Part of a public resolution chain."""
return 5

@ -1005,6 +1005,13 @@ class TestComplexPackage:
assert foo_file.find(id="complex.unicode_data.unicode_str")
def test_nested_parse_directive(self, parse):
package_file = parse("_build/html/autoapi/complex/index.html")
complex = package_file.find(id="complex")
assert "This heading will be removed" not in complex.parent.text
assert complex.parent.find("section")["id"] != "this-heading-will-be-removed"
class TestComplexPackageParallel(TestComplexPackage):
@pytest.fixture(autouse=True, scope="class")

Loading…
Cancel
Save