summaryrefslogtreecommitdiffstats
path: root/Parser
diff options
context:
space:
mode:
authorMiss Islington (bot) <31488909+miss-islington@users.noreply.github.com>2023-07-04 13:00:47 (GMT)
committerGitHub <noreply@github.com>2023-07-04 13:00:47 (GMT)
commit930df7b07e774636ad200a62a7b4b56564f502b0 (patch)
tree795c226b209f041151494ba98b5e9e7309ca7f02 /Parser
parentfda297031bba7c4e46b5959ebaa9c48ca11bb5f4 (diff)
downloadcpython-930df7b07e774636ad200a62a7b4b56564f502b0.zip
cpython-930df7b07e774636ad200a62a7b4b56564f502b0.tar.gz
cpython-930df7b07e774636ad200a62a7b4b56564f502b0.tar.bz2
[3.12] gh-106396: Special-case empty format spec to gen empty JoinedStr node (GH-106401) (#106416)
(cherry picked from commit dfe4de203881e8d068e6fc5b8e31075841a86d25) Co-authored-by: Lysandros Nikolaou <lisandrosnik@gmail.com>
Diffstat (limited to 'Parser')
-rw-r--r--Parser/action_helpers.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/Parser/action_helpers.c b/Parser/action_helpers.c
index dbad56b..e68a9ca 100644
--- a/Parser/action_helpers.c
+++ b/Parser/action_helpers.c
@@ -1003,6 +1003,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;