sphinx-autoapi icon indicating copy to clipboard operation
sphinx-autoapi copied to clipboard

Sphinx Viewcode and autoapi conflict: IndexError list index out of range if child class file (.py) is smaller than parent class file.

Open hansonmcoombs opened this issue 11 months ago • 0 comments

This is a port of an issue from Sphinx (https://github.com/sphinx-doc/sphinx/issues/12026)

The original issue:

Describe the bug

building sphinx the build fails if the child class is smaller than the parent class file.

Error message

../sphinx/ext/viewcode.py", line 289, in collect_pages
    + lines[start])
      ~~~~~^^^^^^^
IndexError: list index out of range

Adding blank lines to the child class (at the end of the file) resolves the problem....

It seems like it must be a rather minimal problem, but it took some time to find the issue

How to Reproduce

The easiest way to reproduce the error is to clone the demo repo I have created: It has full environment information (conda) as well. https://github.com/hansonmcoombs/sphinx_bug_test

Environment Information

Platform:              linux; (Linux-5.15.0-94-generic-x86_64-with-glibc2.35)
Python version:        3.12.2 | packaged by conda-forge | (main, Feb 16 2024, 20:50:58) [GCC 12.3.0])
Python implementation: CPython
Sphinx version:        7.2.6
Docutils version:      0.20.1
Jinja2 version:        3.1.3
Pygments version:      2.17.2

Sphinx extensions

['sphinx.ext.todo', # since found irrelevant  to the issue
 'sphinx.ext.autodoc', # since found irrelevant  to the issue
'sphinx.ext.viewcode',
 'sphinx.ext.autosummary']

Additional learning:

I have slimmed down the example repo:

It appears to be a conflict between autoapi and viewcode extensions, with the following settings:

  • autoapi_options = ['inherited-members']
  • autoapi_python_use_implicit_namespaces = True
  • autoapi_python_class_content = 'both'

I have pushed a commit with the slimmed down example.

hansonmcoombs avatar Mar 03 '24 02:03 hansonmcoombs