diff options
author | Batuhan Taskaya <isidentical@gmail.com> | 2021-05-16 13:33:22 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2021-05-16 13:33:22 (GMT) |
commit | 51cef8be8c77dff522bec6f95d6853031bf19038 (patch) | |
tree | 0203aa036aa29740dfa17b719cdc854db6cf2522 /Lib/test | |
parent | 1a08c5ac49b748d5e4e4b508d22d3804e3cd4dcc (diff) | |
download | cpython-51cef8be8c77dff522bec6f95d6853031bf19038.zip cpython-51cef8be8c77dff522bec6f95d6853031bf19038.tar.gz cpython-51cef8be8c77dff522bec6f95d6853031bf19038.tar.bz2 |
bpo-44142: drop redundant parantheses when unparsing tuples as assignment targets (GH-26156)
Diffstat (limited to 'Lib/test')
-rw-r--r-- | Lib/test/test_ast.py | 3 | ||||
-rw-r--r-- | Lib/test/test_unparse.py | 37 |
2 files changed, 39 insertions, 1 deletions
diff --git a/Lib/test/test_ast.py b/Lib/test/test_ast.py index 80d24e9..249e4bf 100644 --- a/Lib/test/test_ast.py +++ b/Lib/test/test_ast.py @@ -702,7 +702,8 @@ class AST_Tests(unittest.TestCase): def test_precedence_enum(self): class _Precedence(enum.IntEnum): """Precedence table that originated from python grammar.""" - TUPLE = enum.auto() + NAMED_EXPR = enum.auto() # <target> := <expr1> + TUPLE = enum.auto() # <expr1>, <expr2> YIELD = enum.auto() # 'yield', 'yield from' TEST = enum.auto() # 'if'-'else', 'lambda' OR = enum.auto() # 'or' diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index 4d3340e..63151ec 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -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.""" |