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 Bugs fixed
---------- ----------
* #9418: a Callable annotation with no parameters (e.g. Callable[[], None]) will
be rendered with a bracket missing (Callable[], None])
Testing Testing
-------- --------

View File

@ -129,10 +129,14 @@ def _parse_annotation(annotation: str, env: BuildEnvironment = None) -> List[Nod
return unparse(node.value) return unparse(node.value)
elif isinstance(node, ast.List): elif isinstance(node, ast.List):
result = [addnodes.desc_sig_punctuation('', '[')] result = [addnodes.desc_sig_punctuation('', '[')]
for elem in node.elts: if node.elts:
result.extend(unparse(elem)) # check if there are elements in node.elts to only pop the
result.append(addnodes.desc_sig_punctuation('', ', ')) # last element of result if the for-loop was run at least
result.pop() # once
for elem in node.elts:
result.extend(unparse(elem))
result.append(addnodes.desc_sig_punctuation('', ', '))
result.pop()
result.append(addnodes.desc_sig_punctuation('', ']')) result.append(addnodes.desc_sig_punctuation('', ']'))
return result return result
elif isinstance(node, ast.Module): elif isinstance(node, ast.Module):