Skip to content

Commit 0303c25

Browse files
committed
Add snippets to Lib/test/test_ast/snippets.py
1 parent 9cee9ff commit 0303c25

File tree

2 files changed

+17
-1
lines changed

2 files changed

+17
-1
lines changed

Lib/test/test_ast/data/ast_repr.txt

+6-1
Original file line numberDiff line numberDiff line change
@@ -206,4 +206,9 @@ Module(body=[Expr(value=IfExp(test=Name(...), body=Call(...), orelse=Call(...)))
206206
Module(body=[Expr(value=JoinedStr(values=[FormattedValue(...)]))], type_ignores=[])
207207
Module(body=[Expr(value=JoinedStr(values=[FormattedValue(...)]))], type_ignores=[])
208208
Module(body=[Expr(value=JoinedStr(values=[FormattedValue(...)]))], type_ignores=[])
209-
Module(body=[Expr(value=JoinedStr(values=[Constant(...), ..., Constant(...)]))], type_ignores=[])
209+
Module(body=[Expr(value=JoinedStr(values=[Constant(...), ..., Constant(...)]))], type_ignores=[])
210+
Module(body=[Expr(value=TemplateStr(values=[Interpolation(...)]))], type_ignores=[])
211+
Module(body=[Expr(value=TemplateStr(values=[Interpolation(...)]))], type_ignores=[])
212+
Module(body=[Expr(value=TemplateStr(values=[Interpolation(...)]))], type_ignores=[])
213+
Module(body=[Expr(value=TemplateStr(values=[Interpolation(...)]))], type_ignores=[])
214+
Module(body=[Expr(value=TemplateStr(values=[Constant(...), ..., Constant(...)]))], type_ignores=[])

Lib/test/test_ast/snippets.py

+11
Original file line numberDiff line numberDiff line change
@@ -364,6 +364,12 @@
364364
"f'{a:.2f}'",
365365
"f'{a!r}'",
366366
"f'foo({a})'",
367+
# TemplateStr and Interpolation
368+
"t'{a}'",
369+
"t'{a:.2f}'",
370+
"t'{a!r}'",
371+
"t'{a!r:.2f}'",
372+
"t'foo({a})'",
367373
]
368374

369375

@@ -597,5 +603,10 @@ def main():
597603
('Expression', ('JoinedStr', (1, 0, 1, 10), [('FormattedValue', (1, 2, 1, 9), ('Name', (1, 3, 1, 4), 'a', ('Load',)), -1, ('JoinedStr', (1, 4, 1, 8), [('Constant', (1, 5, 1, 8), '.2f', None)]))])),
598604
('Expression', ('JoinedStr', (1, 0, 1, 8), [('FormattedValue', (1, 2, 1, 7), ('Name', (1, 3, 1, 4), 'a', ('Load',)), 114, None)])),
599605
('Expression', ('JoinedStr', (1, 0, 1, 11), [('Constant', (1, 2, 1, 6), 'foo(', None), ('FormattedValue', (1, 6, 1, 9), ('Name', (1, 7, 1, 8), 'a', ('Load',)), -1, None), ('Constant', (1, 9, 1, 10), ')', None)])),
606+
('Expression', ('TemplateStr', (1, 0, 1, 6), [('Interpolation', (1, 2, 1, 5), ('Name', (1, 3, 1, 4), 'a', ('Load',)), 'a', -1, None)])),
607+
('Expression', ('TemplateStr', (1, 0, 1, 10), [('Interpolation', (1, 2, 1, 9), ('Name', (1, 3, 1, 4), 'a', ('Load',)), 'a', -1, ('JoinedStr', (1, 4, 1, 8), [('Constant', (1, 5, 1, 8), '.2f', None)]))])),
608+
('Expression', ('TemplateStr', (1, 0, 1, 8), [('Interpolation', (1, 2, 1, 7), ('Name', (1, 3, 1, 4), 'a', ('Load',)), 'a', 114, None)])),
609+
('Expression', ('TemplateStr', (1, 0, 1, 12), [('Interpolation', (1, 2, 1, 11), ('Name', (1, 3, 1, 4), 'a', ('Load',)), 'a', 114, ('JoinedStr', (1, 6, 1, 10), [('Constant', (1, 7, 1, 10), '.2f', None)]))])),
610+
('Expression', ('TemplateStr', (1, 0, 1, 11), [('Constant', (1, 2, 1, 6), 'foo(', None), ('Interpolation', (1, 6, 1, 9), ('Name', (1, 7, 1, 8), 'a', ('Load',)), 'a', -1, None), ('Constant', (1, 9, 1, 10), ')', None)])),
600611
]
601612
main()

0 commit comments

Comments
 (0)