summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--Lib/ast.py6
-rw-r--r--Lib/test/test_unparse.py3
-rw-r--r--Misc/NEWS.d/next/Library/2022-05-11-19-33-27.gh-issue-92671.KE4v6a.rst1
3 files changed, 9 insertions, 1 deletions
diff --git a/Lib/ast.py b/Lib/ast.py
index e81e280..4e2ae85 100644
--- a/Lib/ast.py
+++ b/Lib/ast.py
@@ -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": "-"}
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py
index f999ae8..969aa16 100644
--- a/Lib/test/test_unparse.py
+++ b/Lib/test/test_unparse.py
@@ -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")
diff --git a/Misc/NEWS.d/next/Library/2022-05-11-19-33-27.gh-issue-92671.KE4v6a.rst b/Misc/NEWS.d/next/Library/2022-05-11-19-33-27.gh-issue-92671.KE4v6a.rst
new file mode 100644
index 0000000..b50677a
--- /dev/null
+++ b/Misc/NEWS.d/next/Library/2022-05-11-19-33-27.gh-issue-92671.KE4v6a.rst
@@ -0,0 +1 @@
+Fixed :func:`ast.unparse` for empty tuples in the assignment target context.