diff options
author | Anthony Shaw <anthony.p.shaw@gmail.com> | 2023-09-05 20:01:23 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-09-05 20:01:23 (GMT) |
commit | 2c4c26c4ce4bb94200ff3c9b5a0f4c75eed96f31 (patch) | |
tree | e4a529b5474595651ee8a002952ccb542c533e65 /Lib/test/test_unparse.py | |
parent | 9bf350b0662fcf1a8b43b9293e6c8ecf3c711561 (diff) | |
download | cpython-2c4c26c4ce4bb94200ff3c9b5a0f4c75eed96f31.zip cpython-2c4c26c4ce4bb94200ff3c9b5a0f4c75eed96f31.tar.gz cpython-2c4c26c4ce4bb94200ff3c9b5a0f4c75eed96f31.tar.bz2 |
gh-108469: Update ast.unparse for unescaped quote support from PEP701 [3.12] (#108553)
Co-authored-by: sunmy2019 <59365878+sunmy2019@users.noreply.github.com>
Diffstat (limited to 'Lib/test/test_unparse.py')
-rw-r--r-- | Lib/test/test_unparse.py | 23 |
1 files changed, 17 insertions, 6 deletions
diff --git a/Lib/test/test_unparse.py b/Lib/test/test_unparse.py index b3efb61..38c59e6 100644 --- a/Lib/test/test_unparse.py +++ b/Lib/test/test_unparse.py @@ -197,6 +197,10 @@ class UnparseTestCase(ASTTestCase): self.check_ast_roundtrip('''f"a\\r\\nb"''') self.check_ast_roundtrip('''f"\\u2028{'x'}"''') + def test_fstrings_pep701(self): + self.check_ast_roundtrip('f" something { my_dict["key"] } something else "') + self.check_ast_roundtrip('f"{f"{f"{f"{f"{f"{1+1}"}"}"}"}"}"') + def test_strings(self): self.check_ast_roundtrip("u'foo'") self.check_ast_roundtrip("r'foo'") @@ -378,8 +382,15 @@ class UnparseTestCase(ASTTestCase): ) ) - def test_invalid_fstring_backslash(self): - self.check_invalid(ast.FormattedValue(value=ast.Constant(value="\\\\"))) + def test_fstring_backslash(self): + # valid since Python 3.12 + self.assertEqual(ast.unparse( + ast.FormattedValue( + value=ast.Constant(value="\\\\"), + conversion=-1, + format_spec=None, + ) + ), "{'\\\\\\\\'}") def test_invalid_yield_from(self): self.check_invalid(ast.YieldFrom(value=None)) @@ -502,11 +513,11 @@ class CosmeticTestCase(ASTTestCase): self.check_src_roundtrip("class X(*args, **kwargs):\n pass") def test_fstrings(self): - self.check_src_roundtrip('''f\'\'\'-{f"""*{f"+{f'.{x}.'}+"}*"""}-\'\'\'''') - self.check_src_roundtrip('''f"\\u2028{'x'}"''') + self.check_src_roundtrip("f'-{f'*{f'+{f'.{x}.'}+'}*'}-'") + self.check_src_roundtrip("f'\\u2028{'x'}'") self.check_src_roundtrip(r"f'{x}\n'") - self.check_src_roundtrip('''f''\'{"""\n"""}\\n''\'''') - self.check_src_roundtrip('''f''\'{f"""{x}\n"""}\\n''\'''') + self.check_src_roundtrip("f'{'\\n'}\\n'") + self.check_src_roundtrip("f'{f'{x}\\n'}\\n'") def test_docstrings(self): docstrings = ( |