Closes #9418: Fix missing bracket for empty Callable annotations.

This commit is contained in:
Thomas Jungers 2021-07-09 16:57:36 +02:00
parent f9644cb080
commit a67105974f
2 changed files with 11 additions and 4 deletions

View File

@ -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
--------

View File

@ -129,6 +129,10 @@ def _parse_annotation(annotation: str, env: BuildEnvironment = None) -> List[Nod
return unparse(node.value)
elif isinstance(node, ast.List):
result = [addnodes.desc_sig_punctuation('', '[')]
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('', ', '))