Describe the bug
call-object is rendered without its doc-string and sphinx-build outputs the following warning on the console (printed at sphinx.ext.autodoc._dynamic/_loader.py, line 145):
WARNING: error while formatting signature for <module>.<call_object>: list assignment index out of range [autodoc]
this bug happens on build when documenting a module containing a callable data object under the following conditions:
- the call-object's class implements
__call__
- the class contains at least one annotated class variable
- the instance is documented using a trailing
#: variable doc-string
How to Reproduce
Minimal reproducer
from typing import Any
class SigBug:
class_var: Any
def __call__(self):
pass
sig_bug = SigBug() #: trigger
Document the module using autosummary / automodule.
Expected behavior
sig_bug should be documented without warnings and should show its docstring ("trigger") in the rendered doc/html/pdf.
Actual behavior
doc-string is not visible in the rendered doc/html/pdf and console shows
WARNING: error while formatting signature for module.sig_bug:
list assignment index out of range [autodoc]
Environment Information
- Sphinx 9.1.0
- Python 3.12.12
Sphinx extensions
Additional context
Debugging
The exception originates from
sphinx/ext/autodoc/_dynamic/_signatures.py
at line 128
signatures[0] = (args, retann if isinstance(retann, str) else '')
At this point the local variables are
props.obj_type == "data"
args == "()"
retann is None
signatures == []
result == ("()", None)
signatures is empty because data objects intentionally skip signature extraction earlier in _format_signatures(), but autodoc-process-signature still returns a replacement signature.
The code assumes that signatures already contains an element although this is not true for obj_type == "data".
A possible fix would be to append a new signature when signatures is empty instead of assigning to signatures[0].
Describe the bug
call-object is rendered without its doc-string and sphinx-build outputs the following warning on the console (printed at
sphinx.ext.autodoc._dynamic/_loader.py, line 145):this bug happens on build when documenting a module containing a callable data object under the following conditions:
__call__#:variable doc-stringHow to Reproduce
Minimal reproducer
Document the module using
autosummary/automodule.Expected behavior
sig_bugshould be documented without warnings and should show its docstring ("trigger") in the rendered doc/html/pdf.Actual behavior
doc-string is not visible in the rendered doc/html/pdf and console shows
Environment Information
Sphinx extensions
autodocAdditional context
Debugging
The exception originates from
at line 128
At this point the local variables are
signaturesis empty because data objects intentionally skip signature extraction earlier in_format_signatures(), butautodoc-process-signaturestill returns a replacement signature.The code assumes that
signaturesalready contains an element although this is not true forobj_type == "data".A possible fix would be to append a new signature when
signaturesis empty instead of assigning tosignatures[0].