summaryrefslogtreecommitdiffstats
path: root/Lib/test/test_unparse.py
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-09-05 20:49:55 (GMT)
committerGitHub <noreply@github.com>2023-09-05 20:49:55 (GMT)
commit495ba70356fc4824aabb7c245b441051dded14e0 (patch)
tree6abcebc7a75ba41db52d50a929c5bc2417536197 /Lib/test/test_unparse.py
parent460043b5548c736ac784e8a09030799322777af0 (diff)
downloadcpython-495ba70356fc4824aabb7c245b441051dded14e0.zip
cpython-495ba70356fc4824aabb7c245b441051dded14e0.tar.gz
cpython-495ba70356fc4824aabb7c245b441051dded14e0.tar.bz2
[3.12] gh-108469: Update ast.unparse for unescaped quote support from PEP701 [3.12] (GH-108553) (#108960)
Co-authored-by: Anthony Shaw <anthony.p.shaw@gmail.com> 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.py23
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 = (