summaryrefslogtreecommitdiffstats
path: root/Parser/action_helpers.c
diff options
context:
space:
mode:
Diffstat (limited to 'Parser/action_helpers.c')
-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 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;