diff --git a/CHANGES b/CHANGES index 486cc2408b7..c91e5b95280 100644 --- a/CHANGES +++ b/CHANGES @@ -16,6 +16,9 @@ Features added Bugs fixed ---------- +* #9418: a Callable annotation with no parameters (e.g. Callable[[], None]) will + be rendered with a bracket missing (Callable[], None]) + Testing -------- diff --git a/sphinx/domains/python.py b/sphinx/domains/python.py index 069737bde29..66e4b13e137 100644 --- a/sphinx/domains/python.py +++ b/sphinx/domains/python.py @@ -129,10 +129,14 @@ def unparse(node: ast.AST) -> List[Node]: return unparse(node.value) elif isinstance(node, ast.List): result = [addnodes.desc_sig_punctuation('', '[')] - for elem in node.elts: - result.extend(unparse(elem)) - result.append(addnodes.desc_sig_punctuation('', ', ')) - result.pop() + if node.elts: + # check if there are elements in node.elts to only pop the + # last element of result if the for-loop was run at least + # once + for elem in node.elts: + result.extend(unparse(elem)) + result.append(addnodes.desc_sig_punctuation('', ', ')) + result.pop() result.append(addnodes.desc_sig_punctuation('', ']')) return result elif isinstance(node, ast.Module):