Skip to content

autodoc: fix crash when a signature handler returns a signature for a data object - #14607

Closed
aryansk wants to merge 1 commit into
sphinx-doc:masterfrom
aryansk:fix-data-signature-handler-crash
Closed

autodoc: fix crash when a signature handler returns a signature for a data object#14607
aryansk wants to merge 1 commit into
sphinx-doc:masterfrom
aryansk:fix-data-signature-handler-crash

Conversation

@aryansk

@aryansk aryansk commented Aug 16, 2026

Copy link
Copy Markdown

Fixes #14576.

What

Documenting a callable data object (e.g. sig_bug = SigBug() with a #: docstring) crashed autodoc when an autodoc-process-signature event handler returned a replacement signature:

WARNING: error while formatting signature for module.sig_bug: list assignment index out of range [autodoc]

Data objects intentionally never get a signature, so signatures is empty when the autodoc-process-signature event fires. The handler's result was assigned to signatures[0], raising IndexError and dropping the object's docstring from the output.

Fix

When the event handler returns a replacement signature and signatures is empty, append it instead of assigning to index 0. Existing behavior (replacing the first signature) is unchanged.

Test

Added test_data_object_signature_from_event_handler, which registers a listener returning ('()', None) for data objects and documents target.callable.function end-to-end. It fails on main with the exact warning above and passes with this change.

Also added a CHANGES.rst entry under the in-development release.

… data object

Data objects never get a signature, but an ``autodoc-process-signature``
event handler may still return a replacement one (e.g. for a callable
data object). The handler's result was assigned to ``signatures[0]`` on an
empty list, raising ``list assignment index out of range`` and dropping
the object's docstring. Append the replacement when no signature exists.

Fixes sphinx-doc#14576.
@jdillard

Copy link
Copy Markdown
Member

Closing as duplicate of #14578

@jdillard jdillard closed this Aug 22, 2026
@aryansk

aryansk commented Aug 23, 2026

Copy link
Copy Markdown
Author

Thanks for the triage @jdillard — closing as a duplicate of #14578 makes sense; that fix covers the same crash. No further action needed from me here (and #14605 remains open if it's still useful).

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

autodoc: IndexError formatting signature for callable data object with annotated class variable

2 participants