summaryrefslogtreecommitdiffstats
path: root/Lib
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-04 13:00:47 (GMT)
committerGitHub <noreply@github.com>2023-07-04 13:00:47 (GMT)
commit930df7b07e774636ad200a62a7b4b56564f502b0 (patch)
tree795c226b209f041151494ba98b5e9e7309ca7f02 /Lib
parentfda297031bba7c4e46b5959ebaa9c48ca11bb5f4 (diff)
downloadcpython-930df7b07e774636ad200a62a7b4b56564f502b0.zip
cpython-930df7b07e774636ad200a62a7b4b56564f502b0.tar.gz
cpython-930df7b07e774636ad200a62a7b4b56564f502b0.tar.bz2
[3.12] gh-106396: Special-case empty format spec to gen empty JoinedStr node (GH-106401) (#106416)
(cherry picked from commit dfe4de203881e8d068e6fc5b8e31075841a86d25) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Lib')
-rw-r--r--Lib/test/test_fstring.py18
1 files changed, 18 insertions, 0 deletions
diff --git a/Lib/test/test_fstring.py b/Lib/test/test_fstring.py
index ba223ae..cb14bba 100644
--- a/Lib/test/test_fstring.py
+++ b/Lib/test/test_fstring.py
@@ -496,6 +496,24 @@ x = (
self.assertEqual(wat2.end_col_offset, 17)
self.assertEqual(fstring.end_col_offset, 18)
+ def test_ast_fstring_empty_format_spec(self):
+ expr = "f'{expr:}'"
+
+ mod = ast.parse(expr)
+ self.assertEqual(type(mod), ast.Module)
+ self.assertEqual(len(mod.body), 1)
+
+ fstring = mod.body[0].value
+ self.assertEqual(type(fstring), ast.JoinedStr)
+ self.assertEqual(len(fstring.values), 1)
+
+ fv = fstring.values[0]
+ self.assertEqual(type(fv), ast.FormattedValue)
+
+ format_spec = fv.format_spec
+ self.assertEqual(type(format_spec), ast.JoinedStr)
+ self.assertEqual(len(format_spec.values), 0)
+
def test_docstring(self):
def f():
f'''Not a docstring'''