diff options
author | Lysandros Nikolaou <lisandrosnik@gmail.com> | 2023-07-04 12:19:08 (GMT) |
---|---|---|
committer | GitHub <noreply@github.com> | 2023-07-04 12:19:08 (GMT) |
commit | dfe4de203881e8d068e6fc5b8e31075841a86d25 (patch) | |
tree | ad3766f442f1175ec072a8d5e5d0fbc28fa85a3f /Parser/action_helpers.c | |
parent | 8f6df5e9cbc3a1689601714192aa6ecbb23e1927 (diff) | |
download | cpython-dfe4de203881e8d068e6fc5b8e31075841a86d25.zip cpython-dfe4de203881e8d068e6fc5b8e31075841a86d25.tar.gz cpython-dfe4de203881e8d068e6fc5b8e31075841a86d25.tar.bz2 |
gh-106396: Special-case empty format spec to gen empty JoinedStr node (#106401)
Diffstat (limited to 'Parser/action_helpers.c')
-rw-r--r-- | Parser/action_helpers.c | 12 |
1 files changed, 12 insertions, 0 deletions
diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c index 70c267b..36e0750 100644 --- a/Parser/action_helpers.c +++ b/Parser/action_helpers.c @@ -997,6 +997,18 @@ _PyPegen_setup_full_format_spec(Parser *p, Token *colon, asdl_expr_seq *spec, in if (!spec) { return NULL; } + + // This is needed to keep compatibility with 3.11, where an empty format spec is parsed + // as an *empty* JoinedStr node, instead of having an empty constant in it. + if (asdl_seq_LEN(spec) == 1) { + expr_ty e = asdl_seq_GET(spec, 0); + if (e->kind == Constant_kind + && PyUnicode_Check(e->v.Constant.value) + && PyUnicode_GetLength(e->v.Constant.value) == 0) { + spec = _Py_asdl_expr_seq_new(0, arena); + } + } + expr_ty res = _PyAST_JoinedStr(spec, lineno, col_offset, end_lineno, end_col_offset, p->arena); if (!res) { return NULL; |