mirror of https://github.com/python/cpython
gh-92671: Don't omit parentheses when unparsing empty tuples (GH-92673)
This commit is contained in:
parent
ca0cc9c433
commit
f6fd8aac13
|
@ -1335,7 +1335,11 @@ class _Unparser(NodeVisitor):
|
|||
)
|
||||
|
||||
def visit_Tuple(self, node):
|
||||
with self.require_parens(_Precedence.TUPLE, node):
|
||||
with self.delimit_if(
|
||||
"(",
|
||||
")",
|
||||
len(node.elts) == 0 or self.get_precedence(node) > _Precedence.TUPLE
|
||||
):
|
||||
self.items_view(self.traverse, node.elts)
|
||||
|
||||
unop = {"Invert": "~", "Not": "not", "UAdd": "+", "USub": "-"}
|
||||
|
|
|
@ -648,6 +648,9 @@ class CosmeticTestCase(ASTTestCase):
|
|||
self.check_src_roundtrip(source.format(target=target))
|
||||
|
||||
def test_star_expr_assign_target_multiple(self):
|
||||
self.check_src_roundtrip("() = []")
|
||||
self.check_src_roundtrip("[] = ()")
|
||||
self.check_src_roundtrip("() = [a] = c, = [d] = e, f = () = g = h")
|
||||
self.check_src_roundtrip("a = b = c = d")
|
||||
self.check_src_roundtrip("a, b = c, d = e, f = g")
|
||||
self.check_src_roundtrip("[a, b] = [c, d] = [e, f] = g")
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
Fixed :func:`ast.unparse` for empty tuples in the assignment target context.
|
Loading…
Reference in New Issue