mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-44142: drop redundant parantheses when unparsing tuples as assignment targets (GH-26156)
This commit is contained in:
parent
1a08c5ac49
commit
51cef8be8c
4 changed files with 47 additions and 4 deletions
|
@ -541,6 +541,43 @@ class CosmeticTestCase(ASTTestCase):
|
|||
self.check_src_roundtrip("lambda x, y, /, z, q, *, u: None")
|
||||
self.check_src_roundtrip("lambda x, *y, **z: None")
|
||||
|
||||
def test_star_expr_assign_target(self):
|
||||
for source_type, source in [
|
||||
("single assignment", "{target} = foo"),
|
||||
("multiple assignment", "{target} = {target} = bar"),
|
||||
("for loop", "for {target} in foo:\n pass"),
|
||||
("async for loop", "async for {target} in foo:\n pass")
|
||||
]:
|
||||
for target in [
|
||||
"a",
|
||||
"a,",
|
||||
"a, b",
|
||||
"a, *b, c",
|
||||
"a, (b, c), d",
|
||||
"a, (b, c, d), *e",
|
||||
"a, (b, *c, d), e",
|
||||
"a, (b, *c, (d, e), f), g",
|
||||
"[a]",
|
||||
"[a, b]",
|
||||
"[a, *b, c]",
|
||||
"[a, [b, c], d]",
|
||||
"[a, [b, c, d], *e]",
|
||||
"[a, [b, *c, d], e]",
|
||||
"[a, [b, *c, [d, e], f], g]",
|
||||
"a, [b, c], d",
|
||||
"[a, b, (c, d), (e, f)]",
|
||||
"a, b, [*c], d, e"
|
||||
]:
|
||||
with self.subTest(source_type=source_type, target=target):
|
||||
self.check_src_roundtrip(source.format(target=target))
|
||||
|
||||
def test_star_expr_assign_target_multiple(self):
|
||||
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")
|
||||
self.check_src_roundtrip("a, b = [c, d] = e, f = g")
|
||||
|
||||
|
||||
|
||||
class DirectoryTestCase(ASTTestCase):
|
||||
"""Test roundtrip behaviour on all files in Lib and Lib/test."""
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue