Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
11 changes: 10 additions & 1 deletion Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1889,7 +1889,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
}
c = tok_nextc(tok);
}
if (c == '"' || c == '\'') {
if ((c == '"' || c == '\'') && !current_tok->f_string_conversion) {
in_tag_string = 1;
goto f_string_quote;
}
Expand Down Expand Up @@ -2225,6 +2225,7 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
the_current_tok->kind = TOK_FSTRING_MODE;
the_current_tok->f_string_quote = quote;
the_current_tok->f_string_quote_size = quote_size;
the_current_tok->f_string_conversion = 0;
the_current_tok->f_string_start = tok->start;
the_current_tok->f_string_multi_line_start = tok->line_start;
the_current_tok->f_string_start_offset = -1;
Expand Down Expand Up @@ -2368,6 +2369,10 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
return MAKE_TOKEN(ENDMARKER);
}

if (c != '!' && current_tok->f_string_conversion) {
current_tok->f_string_conversion = 0;
}

if (c == ':' && cursor == current_tok->curly_bracket_expr_start_depth) {
current_tok->kind = TOK_FSTRING_MODE;
p_start = tok->start;
Expand Down Expand Up @@ -2471,6 +2476,10 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
return MAKE_TOKEN(syntaxerror(tok, "invalid non-printable character U+%s", hex));
}

if (INSIDE_FSTRING_EXPR(current_tok) && c == '!') {
current_tok->f_string_conversion = 1;
}

/* Punctuation character */
p_start = tok->start;
p_end = tok->cur;
Expand Down
2 changes: 2 additions & 0 deletions Parser/tokenizer.h
Original file line number Diff line number Diff line change
Expand Up @@ -52,6 +52,8 @@ typedef struct _tokenizer_mode {
const char* f_string_start;
const char* f_string_multi_line_start;

int f_string_conversion;

Py_ssize_t f_string_start_offset;
Py_ssize_t f_string_multi_line_start_offset;

Expand Down