Fix #7461: autodoc: empty tuple in type annotation is not shown correctly

This commit is contained in:
Takeshi KOMIYA 2020-04-12 13:00:04 +09:00
parent 2e219366c4
commit c8355234eb
3 changed files with 6 additions and 1 deletions

View File

@ -17,6 +17,7 @@ Bugs fixed
----------
* #7461: py domain: fails with IndexError for empty tuple in type annotation
* #7461: autodoc: empty tuple in type annotation is not shown correctly
Testing
--------

View File

@ -114,7 +114,10 @@ def unparse(node: ast.AST) -> str:
elif isinstance(node, ast.UnaryOp):
return "%s %s" % (unparse(node.op), unparse(node.operand))
elif isinstance(node, ast.Tuple):
return ", ".join(unparse(e) for e in node.elts)
if node.elts:
return ", ".join(unparse(e) for e in node.elts)
else:
return "()"
elif sys.version_info > (3, 6) and isinstance(node, ast.Constant):
# this branch should be placed at last
return repr(node.value)

View File

@ -54,6 +54,7 @@ from sphinx.pycode import ast
("- 1", "- 1"), # UnaryOp
("- a", "- a"), # USub
("(1, 2, 3)", "1, 2, 3"), # Tuple
("()", "()"), # Tuple (empty)
])
def test_unparse(source, expected):
module = ast.parse(source)