Store a handler-supplied signature for objects that have none - #14627
Closed
SirHegel wants to merge 1 commit into
Closed
Store a handler-supplied signature for objects that have none#14627SirHegel wants to merge 1 commit into
SirHegel wants to merge 1 commit into
Conversation
_format_signatures reads signatures[0] defensively when emitting autodoc-process-signature, then writes signatures[0] unconditionally with whatever a handler returned. Data and type objects skip signature extraction, so that list is empty for them and the write raises IndexError, which is caught and logged as WARNING: error while formatting signature for mod.obj: list assignment index out of range [autodoc] and the object is rendered without its docstring. Use slice assignment, which stores the signature whether or not one was already extracted. Closes sphinx-doc#14576.
Author
|
Closing — this duplicates work that was already open. #14592 (9 Aug), #14607 (16 Aug) and #14616 (18 Aug) all touch the same lines with the same fix; #14592 is the earliest and came from hitting this in a real docs build. Nothing here that those do not already cover — the only difference is that this used Sorry for the noise. I filtered #14576 on having no assignee and no comments, and did not check whether a PR already referenced it. |
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.
Closes #14576.
The problem
_format_signaturesreadssignatures[0]defensively when emittingautodoc-process-signature:and then writes
signatures[0]unconditionally. Data and type objects skip signature extraction, so for them that list is empty and the write raisesIndexError. It is caught and logged, and the object loses its docstring:The reporter diagnosed this precisely in the issue; I reproduced it with their module and a
conf.pyhandler, which is the documented way to use the event:Before: the warning above, and
trigger(the#:docstring) appears 0 times in the built HTML.After:
build succeeded., andtriggerappears 1 time.The change
signatures[:1] = [...]instead ofsignatures[0] = .... Slice assignment stores the signature whether or not one was already extracted, and is identical to the old behaviour when the list is non-empty.The
if props.obj_type in {'module', 'data', 'type'}: signatures[1:] = ()a few lines below already uses the same idiom for the same reason.Tests
test_format_signatures_event_handler_on_dataintests/test_ext_autodoc/test_ext_autodoc_signatures.py. Onmasterit fails with the exact error from the issue:tests/test_ext_autodoc/goes from4 failed, 222 passedto4 failed, 223 passed. The four failures are present on unmodifiedmasterhere as well — they are Python 3.14 import failures intest_autodoc_pep695_type_alias,test_final,test_overload3andtest_import_native_module_stubs, unrelated to this change.ruff checkreports the same 9 pre-existing findings before and after;ruff format --checkis clean.AI disclosure
Claude (Opus 5) was used to locate the code, draft the change and the test, and write this description. I built the reproducer and ran the before/after builds myself, checked that the four suite failures predate the change by running the suite on a clean checkout, and confirmed the new test fails without the fix. Happy to answer questions on it.