summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-12 13:00:04 +0900
committerTakeshi KOMIYA <i.tkomiya@gmail.com>2020-04-12 13:00:04 +0900
commitc8355234ebc63258004ad06da6bcf9dd7b98fac3 (patch)
tree2acdcd8b6f60fff6a1310294ee0180426bd2d0cb
parent2e219366c433deb56fd3311a9245cdbabac05ca6 (diff)
downloadsphinx-git-c8355234ebc63258004ad06da6bcf9dd7b98fac3.tar.gz
Fix #7461: autodoc: empty tuple in type annotation is not shown correctly
-rw-r--r--CHANGES1
-rw-r--r--sphinx/pycode/ast.py5
-rw-r--r--tests/test_pycode_ast.py1
3 files changed, 6 insertions, 1 deletions
diff --git a/CHANGES b/CHANGES
index 31bc95082..7a813f802 100644
--- a/CHANGES
+++ b/CHANGES
@@ -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
--------
diff --git a/sphinx/pycode/ast.py b/sphinx/pycode/ast.py
index 4d8aa8955..fb2a7152d 100644
--- a/sphinx/pycode/ast.py
+++ b/sphinx/pycode/ast.py
@@ -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)
diff --git a/tests/test_pycode_ast.py b/tests/test_pycode_ast.py
index 117feb8f7..9b12d24d5 100644
--- a/tests/test_pycode_ast.py
+++ b/tests/test_pycode_ast.py
@@ -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)