mirror of
https://github.com/python/cpython.git
synced 2025-08-10 03:49:18 +00:00
[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:
parent
fda297031b
commit
930df7b07e
3 changed files with 33 additions and 0 deletions
|
@ -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'''
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue