mirror of
https://github.com/python/cpython.git
synced 2025-10-07 07:31:46 +00:00
bpo-43417: Better buffer handling for ast.unparse (GH-24772)
This commit is contained in:
parent
a0bd9e9c11
commit
3d98ececda
2 changed files with 87 additions and 66 deletions
|
@ -149,6 +149,27 @@ class UnparseTestCase(ASTTestCase):
|
|||
# Tests for specific bugs found in earlier versions of unparse
|
||||
|
||||
def test_fstrings(self):
|
||||
self.check_ast_roundtrip("f'a'")
|
||||
self.check_ast_roundtrip("f'{{}}'")
|
||||
self.check_ast_roundtrip("f'{{5}}'")
|
||||
self.check_ast_roundtrip("f'{{5}}5'")
|
||||
self.check_ast_roundtrip("f'X{{}}X'")
|
||||
self.check_ast_roundtrip("f'{a}'")
|
||||
self.check_ast_roundtrip("f'{ {1:2}}'")
|
||||
self.check_ast_roundtrip("f'a{a}a'")
|
||||
self.check_ast_roundtrip("f'a{a}{a}a'")
|
||||
self.check_ast_roundtrip("f'a{a}a{a}a'")
|
||||
self.check_ast_roundtrip("f'{a!r}x{a!s}12{{}}{a!a}'")
|
||||
self.check_ast_roundtrip("f'{a:10}'")
|
||||
self.check_ast_roundtrip("f'{a:100_000{10}}'")
|
||||
self.check_ast_roundtrip("f'{a!r:10}'")
|
||||
self.check_ast_roundtrip("f'{a:a{b}10}'")
|
||||
self.check_ast_roundtrip(
|
||||
"f'a{b}{c!s}{d!r}{e!a}{f:a}{g:a{b}}{h!s:a}"
|
||||
"{j!s:{a}b}{k!s:a{b}c}{l!a:{b}c{d}}{x+y=}'"
|
||||
)
|
||||
|
||||
def test_fstrings_special_chars(self):
|
||||
# See issue 25180
|
||||
self.check_ast_roundtrip(r"""f'{f"{0}"*3}'""")
|
||||
self.check_ast_roundtrip(r"""f'{f"{y}"*3}'""")
|
||||
|
@ -323,15 +344,13 @@ class UnparseTestCase(ASTTestCase):
|
|||
def test_invalid_raise(self):
|
||||
self.check_invalid(ast.Raise(exc=None, cause=ast.Name(id="X")))
|
||||
|
||||
def test_invalid_fstring_constant(self):
|
||||
self.check_invalid(ast.JoinedStr(values=[ast.Constant(value=100)]))
|
||||
|
||||
def test_invalid_fstring_conversion(self):
|
||||
def test_invalid_fstring_value(self):
|
||||
self.check_invalid(
|
||||
ast.FormattedValue(
|
||||
value=ast.Constant(value="a", kind=None),
|
||||
conversion=ord("Y"), # random character
|
||||
format_spec=None,
|
||||
ast.JoinedStr(
|
||||
values=[
|
||||
ast.Name(id="test"),
|
||||
ast.Constant(value="test")
|
||||
]
|
||||
)
|
||||
)
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue