Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Extension error: list index out of range #412

Closed
mcflugen opened this issue Nov 8, 2023 · 5 comments
Closed

Extension error: list index out of range #412

mcflugen opened this issue Nov 8, 2023 · 5 comments
Labels
Bug Good First Issue Good issue for first time contributors

Comments

@mcflugen
Copy link

mcflugen commented Nov 8, 2023

👋 Hello!

When trying to build documentation for my project using sphinx-autoapi, I'm getting the following error,

Extension error (sphinx.environment.collectors.toctree):
Handler <bound method TocTreeCollector.process_doc of <sphinx.environment.collectors.toctree.TocTreeCollector object at 0x103570680>> for event 'doctree-read' threw an exception (exception: list index out of range)

After digging around a bit, it appears the problem may lie in NestedParse when it removes a heading. Although the title node is removed with del node[0][0], perhaps the number of nodes is not decremented somewhere, which causes sphinx to try to iterate beyond the end of the list?

Anyway, below is a minimal reproducible example that produces the error (for me, anyway).

# file: docs/conf.py
extensions = ["autoapi.extension"]
autoapi_dirs = ['../foobar']
# file: foobar/foo.py
"""
This is a heading
=================
"""

Running the following generates the above error,

sphinx-build -b html docs/ _build/html

If I either remove the heading in foobar/foo.py or remove the del node[0][0] line from NestedParse, the error goes away and the docs build successfully.

I'm using sphinx-autoapi v3.0.0 and sphinx v7.2.6.

Any ideas? Am I missing something?

Thanks!

@mcflugen
Copy link
Author

mcflugen commented Nov 9, 2023

Popping the first child off the title_node's children seems to fix the issue—no ExtensionError and the heading is removed from the rendered html. If this seems like a reasonable fix to you, I'm happy to submit a pull request.

diff --git a/autoapi/directives.py b/autoapi/directives.py
index ee5e3ec..fb6caa2 100644
--- a/autoapi/directives.py
+++ b/autoapi/directives.py
@@ -61,7 +61,7 @@ class NestedParse(Directive):
         try:
             title_node = node[0][0]
             if isinstance(title_node, nodes.title):
-                del node[0][0]
+                title_node.children.pop(0)
         except IndexError:
             pass
         return node.children

@mcflugen mcflugen changed the title Extension error: lint index out of range Extension error: list index out of range Nov 17, 2023
@AWhetter
Copy link
Collaborator

AWhetter commented Dec 2, 2023

That sounds like a good fix to me!

@AWhetter AWhetter added Bug Good First Issue Good issue for first time contributors labels Dec 2, 2023
@pbrod
Copy link

pbrod commented Feb 9, 2024

I am experiencing the same error when building the documentation for karney package:

https://readthedocs.org/projects/karney/builds/23394851/

Any chance it can be fixed in the next release?

@AWhetter
Copy link
Collaborator

Fixed in c4db7eb

@BrandonLiang
Copy link

Hi, when is thew version planned to be released?

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Bug Good First Issue Good issue for first time contributors
Projects
None yet
Development

No branches or pull requests

4 participants