mirror of
https://github.com/python/cpython.git
synced 2025-08-04 08:59:19 +00:00
bpo-38870: Don't omit parenthesis when unparsing a slice in ast.unparse
When unparsing a non-empty tuple, the parentheses can be safely omitted if there aren't any elements that explicitly require them (such as starred expressions).
This commit is contained in:
parent
75b863aa97
commit
c102a14825
2 changed files with 20 additions and 2 deletions
|
@ -279,10 +279,13 @@ class UnparseTestCase(ASTTestCase):
|
|||
self.check_ast_roundtrip(r"""{**{'y': 2}, 'x': 1}""")
|
||||
self.check_ast_roundtrip(r"""{**{'y': 2}, **{'x': 1}}""")
|
||||
|
||||
def test_ext_slices(self):
|
||||
def test_slices(self):
|
||||
self.check_ast_roundtrip("a[i]")
|
||||
self.check_ast_roundtrip("a[i,]")
|
||||
self.check_ast_roundtrip("a[i, j]")
|
||||
self.check_ast_roundtrip("a[(*a,)]")
|
||||
self.check_ast_roundtrip("a[(a:=b)]")
|
||||
self.check_ast_roundtrip("a[(a:=b,c)]")
|
||||
self.check_ast_roundtrip("a[()]")
|
||||
self.check_ast_roundtrip("a[i:j]")
|
||||
self.check_ast_roundtrip("a[:j]")
|
||||
|
@ -470,6 +473,11 @@ class CosmeticTestCase(ASTTestCase):
|
|||
for prefix in ("not",):
|
||||
self.check_src_roundtrip(f"{prefix} 1")
|
||||
|
||||
def test_slices(self):
|
||||
self.check_src_roundtrip("a[1]")
|
||||
self.check_src_roundtrip("a[1, 2]")
|
||||
self.check_src_roundtrip("a[(1, *a)]")
|
||||
|
||||
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