diff options
author | Matthew Rahtz <matthew.rahtz@gmail.com> | 2022-03-26 16:55:35 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2022-03-26 16:55:35 (GMT) |
commit | e8e737bcf6d22927caebc30c5d57ac4634063219 (patch) | |
tree | 6c0d4d51e8216f02fa0e6874aa4d78e20dd9397a /Lib/test/test_unparse.py | |
parent | 26cca8067bf5306e372c0e90036d832c5021fd90 (diff) | |
download | cpython-e8e737bcf6d22927caebc30c5d57ac4634063219.zip cpython-e8e737bcf6d22927caebc30c5d57ac4634063219.tar.gz cpython-e8e737bcf6d22927caebc30c5d57ac4634063219.tar.bz2 |
bpo-43224: Implement PEP 646 grammar changes (GH-31018)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
Diffstat (limited to 'Lib/test/test_unparse.py')
-rw-r--r-- | Lib/test/test_unparse.py | 26 |
1 files changed, 25 insertions, 1 deletions
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index f5be13a..e38b335 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -344,7 +344,17 @@ class UnparseTestCase(ASTTestCase): self.check_ast_roundtrip("a[i]") self.check_ast_roundtrip("a[i,]") self.check_ast_roundtrip("a[i, j]") + # The AST for these next two both look like `a[(*a,)]` self.check_ast_roundtrip("a[(*a,)]") + self.check_ast_roundtrip("a[*a]") + self.check_ast_roundtrip("a[b, *a]") + self.check_ast_roundtrip("a[*a, c]") + self.check_ast_roundtrip("a[b, *a, c]") + self.check_ast_roundtrip("a[*a, *a]") + self.check_ast_roundtrip("a[b, *a, *a]") + self.check_ast_roundtrip("a[*a, b, *a]") + self.check_ast_roundtrip("a[*a, *a, b]") + self.check_ast_roundtrip("a[b, *a, *a, c]") self.check_ast_roundtrip("a[(a:=b)]") self.check_ast_roundtrip("a[(a:=b,c)]") self.check_ast_roundtrip("a[()]") @@ -543,9 +553,23 @@ class CosmeticTestCase(ASTTestCase): self.check_src_roundtrip(f"{prefix} 1") def test_slices(self): + self.check_src_roundtrip("a[()]") self.check_src_roundtrip("a[1]") self.check_src_roundtrip("a[1, 2]") - self.check_src_roundtrip("a[(1, *a)]") + # Note that `a[*a]`, `a[*a,]`, and `a[(*a,)]` all evaluate to the same + # thing at runtime and have the same AST, but only `a[*a,]` passes + # this test, because that's what `ast.unparse` produces. + self.check_src_roundtrip("a[*a,]") + self.check_src_roundtrip("a[1, *a]") + self.check_src_roundtrip("a[*a, 2]") + self.check_src_roundtrip("a[1, *a, 2]") + self.check_src_roundtrip("a[*a, *a]") + self.check_src_roundtrip("a[1, *a, *a]") + self.check_src_roundtrip("a[*a, 1, *a]") + self.check_src_roundtrip("a[*a, *a, 1]") + self.check_src_roundtrip("a[1, *a, *a, 2]") + self.check_src_roundtrip("a[1:2, *a]") + self.check_src_roundtrip("a[*a, 1:2]") def test_lambda_parameters(self): self.check_src_roundtrip("lambda: something") |