Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix #9364: autodoc: 1-element tuple on the defarg is wrongly rendered #9367

Merged
merged 1 commit into from Jun 30, 2021
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
2 changes: 2 additions & 0 deletions CHANGES
Expand Up @@ -65,6 +65,8 @@ Bugs fixed
* #9250: autodoc: The inherited method not having docstring is wrongly parsed
* #9283: autodoc: autoattribute directive failed to generate document for an
attribute not having any comment
* #9364: autodoc: single element tuple on the default argument value is wrongly
rendered
* #9317: html: Pushing left key causes visiting the next page at the first page
* #9270: html theme : pyramid theme generates incorrect logo links
* #9217: manpage: The name of manpage directory that is generated by
Expand Down
8 changes: 5 additions & 3 deletions sphinx/pycode/ast.py
Expand Up @@ -213,10 +213,12 @@ def visit_UnaryOp(self, node: ast.UnaryOp) -> str:
return "%s %s" % (self.visit(node.op), self.visit(node.operand))

def visit_Tuple(self, node: ast.Tuple) -> str:
if node.elts:
return "(" + ", ".join(self.visit(e) for e in node.elts) + ")"
else:
if len(node.elts) == 0:
return "()"
elif len(node.elts) == 1:
return "(%s,)" % self.visit(node.elts[0])
else:
return "(" + ", ".join(self.visit(e) for e in node.elts) + ")"

if sys.version_info < (3, 8):
# these ast nodes were deprecated in python 3.8
Expand Down
3 changes: 2 additions & 1 deletion tests/test_pycode_ast.py
Expand Up @@ -53,8 +53,9 @@
("+ a", "+ a"), # UAdd
("- 1", "- 1"), # UnaryOp
("- a", "- a"), # USub
("(1, 2, 3)", "(1, 2, 3)"), # Tuple
("(1, 2, 3)", "(1, 2, 3)"), # Tuple
("()", "()"), # Tuple (empty)
("(1,)", "(1,)"), # Tuple (single item)
])
def test_unparse(source, expected):
module = ast.parse(source)
Expand Down