autodoc: fix IndexError when an event handler supplies a signature - #14578
Open
UlikGames wants to merge 2 commits into
Open
autodoc: fix IndexError when an event handler supplies a signature#14578UlikGames wants to merge 2 commits into
UlikGames wants to merge 2 commits into
Conversation
Member
|
Closing until the PR description is updated in accordance with the AI policy, which is intended to ensure appropriate human oversight. I can reopen once the description is updated. |
|
FWIW, I was getting the same error message when using this def add_pep695_generics_to_signature(
app, obj_type, name, obj, options, signature, return_annotation
):
if (
obj_type in ('class', 'function', 'method')
and hasattr(obj, "__type_params__")
and len(obj.__type_params__) > 0
):
params = f"[{', '.join(p.__name__ for p in obj.__type_params__)}]"
if signature is not None:
signature = params + signature
else:
signature = params + '()'
return signature, return_annotationWith this change the error is gone and the hook works. |
Contributor
|
I opened a similar PR in #14592 , I think the tests from there could be ported over here! |
Author
This was referenced Aug 22, 2026
larsoner
approved these changes
Aug 22, 2026
larsoner
left a comment
Contributor
There was a problem hiding this comment.
Same fix in principle as mine but simpler and has a superset of my tests, +1 for merge from me!
3 tasks
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
Previously,
_format_signatureswould run into trouble when it received an emptysignatureslist - something that naturally occurs with data, modules, type aliases, and attributes, since_get_signature_objectdoesn’t process these types.When a custom event handler supplied a signature for one of these items, the code tried to update the first entry using
signatures[0] = .... But if the list was empty, this triggered anIndexError, resulting in a warning and leaving both signature and docstring ungenerated.This update replaces that approach with
signatures[:1] = ..., a more flexible method that either adds the signature when the list is empty or replaces the first item if one exists - handling both cases smoothly.Also worth noting: while the original report pointed to annotated class variables, they may not be the core issue. The same problem can occur with objects that have no annotations at all, or when a signature is provided via an event handler for something that previously had none.
New tests covering data, modules, type aliases, and attributes have been included, and everything runs successfully in local testing.
AI usage disclosure
Tool used: Claude Opus 5
How it was used: to run all of the tests, helping us ensure everything worked smoothly
Tool used: Codex Sol 5.6
How it was used: to refine the grammar and make the pull request description clearer.
After suggestion from @jdillard asked(which I truly appreciated), I took the time to rewrite the description personally.