Skip to content

Commit c4db7eb

Browse files
committed
Fix IndexError when a module docstring contains only a heading
1 parent 422004e commit c4db7eb

File tree

5 files changed

+25
-3
lines changed

5 files changed

+25
-3
lines changed

autoapi/directives.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -58,9 +58,10 @@ def run(self):
5858
node.document = self.state.document
5959
nested_parse_with_titles(self.state, self.content, node)
6060
try:
61-
title_node = node[0][0]
62-
if isinstance(title_node, nodes.title):
63-
del node[0][0]
61+
if isinstance(node[0], nodes.section) and isinstance(
62+
node[0][0], nodes.title
63+
):
64+
node.children = node[0][1:] + node.children[1:]
6465
except IndexError:
6566
pass
6667
return node.children

docs/changes/412.bugfix

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1 @@
1+
Fix IndexError when a module docstring contains only a heading

tests/python/pypackagecomplex/complex/__init__.py

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,8 @@
1+
"""
2+
This heading will be removed
3+
============================
4+
"""
5+
16
from .subpackage import public_chain
27
from .subpackage.submodule import public_multiple_imports
38

tests/python/pypackagecomplex/complex/subpackage/submodule.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,3 +1,11 @@
1+
"""
2+
This heading will be removed
3+
============================
4+
5+
This docstring will not be removed.
6+
"""
7+
8+
19
def public_chain():
210
"""Part of a public resolution chain."""
311
return 5

tests/python/test_pyintegration.py

Lines changed: 7 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1005,6 +1005,13 @@ def test_parses_unicode_file(self, parse):
10051005

10061006
assert foo_file.find(id="complex.unicode_data.unicode_str")
10071007

1008+
def test_nested_parse_directive(self, parse):
1009+
package_file = parse("_build/html/autoapi/complex/index.html")
1010+
1011+
complex = package_file.find(id="complex")
1012+
assert "This heading will be removed" not in complex.parent.text
1013+
assert complex.parent.find("section")["id"] != "this-heading-will-be-removed"
1014+
10081015

10091016
class TestComplexPackageParallel(TestComplexPackage):
10101017
@pytest.fixture(autouse=True, scope="class")

0 commit comments

Comments
 (0)