mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-43224: Implement PEP 646 grammar changes (GH-31018)
Co-authored-by: Jelle Zijlstra <jelle.zijlstra@gmail.com>
This commit is contained in:
parent
26cca8067b
commit
e8e737bcf6
12 changed files with 4324 additions and 3396 deletions
|
@ -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")
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue