[3.12] gh-106396: Special-case empty format spec to gen empty JoinedStr node (GH-106401) (#106416)

(cherry picked from commit dfe4de2038)

Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
This commit is contained in:
Miss Islington (bot) 2023-07-04 06:00:47 -07:00 committed by GitHub
parent fda297031b
commit 930df7b07e
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 33 additions and 0 deletions

View file

@ -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'''