Skip to content

Commit

Permalink
Fix sphinx-doc#7461: autodoc: empty tuple in type annotation is not s…
Browse files Browse the repository at this point in the history
…hown correctly
  • Loading branch information
tk0miya committed Apr 12, 2020
1 parent 2e21936 commit c835523
Show file tree
Hide file tree
Showing 3 changed files with 6 additions and 1 deletion.
1 change: 1 addition & 0 deletions CHANGES
Expand Up @@ -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
--------
Expand Down
5 changes: 4 additions & 1 deletion sphinx/pycode/ast.py
Expand Up @@ -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)
Expand Down
1 change: 1 addition & 0 deletions tests/test_pycode_ast.py
Expand Up @@ -54,6 +54,7 @@
("- 1", "- 1"), # UnaryOp
("- a", "- a"), # USub
("(1, 2, 3)", "1, 2, 3"), # Tuple
("()", "()"), # Tuple (empty)
])
def test_unparse(source, expected):
module = ast.parse(source)
Expand Down

0 comments on commit c835523

Please sign in to comment.