diff options
Diffstat (limited to 'Python')
-rw-r--r-- | Python/ast.c | 11 | ||||
-rw-r--r-- | Python/compile.c | 3 |
2 files changed, 7 insertions, 7 deletions
diff --git a/Python/ast.c b/Python/ast.c index e6786d47f9..f07bb1685c 100644 --- a/Python/ast.c +++ b/Python/ast.c @@ -4784,6 +4784,7 @@ ExprList_Finish(ExprList *l, PyArena *arena) typedef struct { PyObject *last_str; ExprList expr_list; + int fmode; } FstringParser; #ifdef NDEBUG @@ -4802,6 +4803,7 @@ static void FstringParser_Init(FstringParser *state) { state->last_str = NULL; + state->fmode = 0; ExprList_Init(&state->expr_list); FstringParser_check_invariants(state); } @@ -4864,6 +4866,7 @@ FstringParser_ConcatFstring(FstringParser *state, const char **str, struct compiling *c, const node *n) { FstringParser_check_invariants(state); + state->fmode = 1; /* Parse the f-string. */ while (1) { @@ -4955,7 +4958,8 @@ FstringParser_Finish(FstringParser *state, struct compiling *c, /* If we're just a constant string with no expressions, return that. */ - if(state->expr_list.size == 0) { + if (!state->fmode) { + assert(!state->expr_list.size); if (!state->last_str) { /* Create a zero length string. */ state->last_str = PyUnicode_FromStringAndSize(NULL, 0); @@ -4979,11 +4983,6 @@ FstringParser_Finish(FstringParser *state, struct compiling *c, if (!seq) goto error; - /* If there's only one expression, return it. Otherwise, we need - to join them together. */ - if (seq->size == 1) - return seq->elements[0]; - return JoinedStr(seq, LINENO(n), n->n_col_offset, c->c_arena); error: diff --git a/Python/compile.c b/Python/compile.c index 76f08da432..f4edf8fd88 100644 --- a/Python/compile.c +++ b/Python/compile.c @@ -3412,7 +3412,8 @@ static int compiler_joined_str(struct compiler *c, expr_ty e) { VISIT_SEQ(c, expr, e->v.JoinedStr.values); - ADDOP_I(c, BUILD_STRING, asdl_seq_LEN(e->v.JoinedStr.values)); + if (asdl_seq_LEN(e->v.JoinedStr.values) != 1) + ADDOP_I(c, BUILD_STRING, asdl_seq_LEN(e->v.JoinedStr.values)); return 1; } |