autodoc: fix crash when a signature handler returns a signature for a data object - #14607
Closed
aryansk wants to merge 1 commit into
Closed
autodoc: fix crash when a signature handler returns a signature for a data object#14607aryansk wants to merge 1 commit into
aryansk wants to merge 1 commit into
Conversation
… 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.
Member
|
Closing as duplicate of #14578 |
Author
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #14576.
What
Documenting a callable data object (e.g.
sig_bug = SigBug()with a#:docstring) crashed autodoc when anautodoc-process-signatureevent handler returned a replacement signature:Data objects intentionally never get a signature, so
signaturesis empty when theautodoc-process-signatureevent fires. The handler's result was assigned tosignatures[0], raisingIndexErrorand dropping the object's docstring from the output.Fix
When the event handler returns a replacement signature and
signaturesis 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)fordataobjects and documentstarget.callable.functionend-to-end. It fails on main with the exact warning above and passes with this change.Also added a
CHANGES.rstentry under the in-development release.