8000 gh-92671: Don't omit parentheses when unparsing empty tuples by isidentical · Pull Request #92673 · python/cpython · GitHub
[go: up one dir, main page]

Skip to content

gh-92671: Don't omit parentheses when unparsing empty tuples #92673

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

Merged
merged 2 commits into from
May 16, 2022
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.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
6 changes: 5 additions & 1 deletion Lib/ast.py
Original file line number Diff line number Diff line change
Expand Up @@ -1335,7 +1335,11 @@ def write_item(item):
)

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": "-"}
Expand Down
3 changes: 3 additions & 0 deletions Lib/test/test_unparse.py
Original file line number Diff line number Diff line change
Expand Up @@ -648,6 +648,9 @@ def test_star_expr_assign_target(self):
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")
Expand Down
38AF
Original file line number Diff line number Diff line change
@@ -0,0 +1 @@
Fixed :func:`ast.unparse` for empty tuples in the assignment target context.
0