@@ -4789,6 +4789,7 @@ ExprList_Finish(ExprList *l, PyArena *arena)
47894789typedef struct {
47904790 PyObject * last_str ;
47914791 ExprList expr_list ;
4792+ int fmode ;
47924793} FstringParser ;
47934794
47944795#ifdef NDEBUG
@@ -4807,6 +4808,7 @@ static void
48074808FstringParser_Init (FstringParser * state )
48084809{
48094810 state -> last_str = NULL ;
4811+ state -> fmode = 0 ;
48104812 ExprList_Init (& state -> expr_list );
48114813 FstringParser_check_invariants (state );
48124814}
@@ -4869,6 +4871,7 @@ FstringParser_ConcatFstring(FstringParser *state, const char **str,
48694871 struct compiling * c , const node * n )
48704872{
48714873 FstringParser_check_invariants (state );
4874+ state -> fmode = 1 ;
48724875
48734876 /* Parse the f-string. */
48744877 while (1 ) {
@@ -4960,7 +4963,8 @@ FstringParser_Finish(FstringParser *state, struct compiling *c,
49604963
49614964 /* If we're just a constant string with no expressions, return
49624965 that. */
4963- if (state -> expr_list .size == 0 ) {
4966+ if (!state -> fmode ) {
4967+ assert (!state -> expr_list .size );
49644968 if (!state -> last_str ) {
49654969 /* Create a zero length string. */
49664970 state -> last_str = PyUnicode_FromStringAndSize (NULL , 0 );
@@ -4984,11 +4988,6 @@ FstringParser_Finish(FstringParser *state, struct compiling *c,
49844988 if (!seq )
49854989 goto error ;
49864990
4987- /* If there's only one expression, return it. Otherwise, we need
4988- to join them together. */
4989- if (seq -> size == 1 )
4990- return seq -> elements [0 ];
4991-
49924991 return JoinedStr (seq , LINENO (n ), n -> n_col_offset , c -> c_arena );
49934992
49944993error :
0 commit comments