mirror of
https://github.com/python/cpython.git
synced 2025-09-24 17:33:29 +00:00
[3.12] gh-122300: Preserve AST nodes for format specifiers with single elements (GH-122308) (#122363)
(cherry picked from commit db2d8b6db1
)
This commit is contained in:
parent
8205c16c7c
commit
ca3486cb1e
4 changed files with 133 additions and 2826 deletions
|
@ -302,7 +302,9 @@ Literals
|
|||
Name(id='a', ctx=Load())],
|
||||
keywords=[]),
|
||||
conversion=-1,
|
||||
format_spec=Constant(value='.3'))]))
|
||||
format_spec=JoinedStr(
|
||||
values=[
|
||||
Constant(value='.3')]))]))
|
||||
|
||||
|
||||
.. class:: List(elts, ctx)
|
||||
|
|
2950
Lib/test/test_ast.py
2950
Lib/test/test_ast.py
File diff suppressed because it is too large
Load diff
|
@ -0,0 +1,2 @@
|
|||
Preserve AST nodes for f-string with single-element format specifiers. Patch
|
||||
by Pablo Galindo
|
|
@ -928,7 +928,8 @@ _PyPegen_setup_full_format_spec(Parser *p, Token *colon, asdl_expr_seq *spec,
|
|||
}
|
||||
}
|
||||
expr_ty res;
|
||||
if (asdl_seq_LEN(spec) == 0) {
|
||||
Py_ssize_t n = asdl_seq_LEN(spec);
|
||||
if (n == 0 || (n == 1 && asdl_seq_GET(spec, 0)->kind == Constant_kind)) {
|
||||
res = _PyAST_JoinedStr(spec, lineno, col_offset, end_lineno, end_col_offset,
|
||||
p->arena);
|
||||
} else {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue