mirror of
https://github.com/sphinx-doc/sphinx.git
synced 2025-02-25 18:55:22 -06:00
Merge pull request #9367 from tk0miya/9364_single_element_tuple
Fix #9364: autodoc: 1-element tuple on the defarg is wrongly rendered
This commit is contained in:
commit
bc616d3b1a
2
CHANGES
2
CHANGES
@ -77,6 +77,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
|
||||
* #9381: html: URL for html_favicon and html_log does not work
|
||||
* #9270: html theme : pyramid theme generates incorrect logo links
|
||||
|
@ -213,10 +213,12 @@ class _UnparseVisitor(ast.NodeVisitor):
|
||||
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
|
||||
|
@ -53,8 +53,9 @@ from sphinx.pycode import ast
|
||||
("+ 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)
|
||||
|
Loading…
Reference in New Issue
Block a user