Skip to content

Commit

Permalink
Closes #9418: Fix missing bracket for empty Callable annotations.
Browse files Browse the repository at this point in the history
  • Loading branch information
Thomas Jungers committed Jul 9, 2021
1 parent f9644cb commit a671059
Show file tree
Hide file tree
Showing 2 changed files with 11 additions and 4 deletions.
3 changes: 3 additions & 0 deletions CHANGES
Original file line number Diff line number Diff line change
Expand Up @@ -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
--------

Expand Down
12 changes: 8 additions & 4 deletions sphinx/domains/python.py
Original file line number Diff line number Diff line change
Expand Up @@ -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):
Expand Down

0 comments on commit a671059

Please sign in to comment.