Skip to content

Commit f5e9e87

Browse files
committed
gh-102856: Allow comments inside multi-line f-string expresions
1 parent cdd491c commit f5e9e87

File tree

1 file changed

+6
-2
lines changed

1 file changed

+6
-2
lines changed

Parser/tokenizer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1795,8 +1795,12 @@ tok_get_normal_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct t
17951795

17961796
// We don't allow # inside a one-line f-string expr,
17971797
// but we do in multi-line f-string expr
1798-
if (INSIDE_FSTRING(tok) && (tok->lineno == 1)) {
1799-
return MAKE_TOKEN(syntaxerror(tok, "f-string expression part cannot include '#'"));
1798+
if (INSIDE_FSTRING(tok) && (current_tok->f_string_quote_size == 1)) {
1799+
while (c != '\n') {
1800+
c = tok_nextc(tok);
1801+
if (c == '}')
1802+
return MAKE_TOKEN(syntaxerror(tok, "single line f-string expression part cannot include '#'"));
1803+
}
18001804
}
18011805

18021806
const char *prefix, *p, *type_start;

0 commit comments

Comments
 (0)