Skip to content

Commit 3003fbb

Browse files
authored
gh-113703: Correctly identify incomplete f-strings in the codeop module (#113709)
1 parent 0ae60b6 commit 3003fbb

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Lib/test/test_codeop.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -223,6 +223,9 @@ def test_incomplete(self):
223223
ai("(x for x in")
224224
ai("(x for x in (")
225225

226+
ai('a = f"""')
227+
ai('a = \\')
228+
226229
def test_invalid(self):
227230
ai = self.assertInvalid
228231
ai("a b")
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a regression in the :mod:`codeop` module that was causing it to incorrectly
2+
identify incomplete f-strings. Patch by Pablo Galindo

Parser/lexer/lexer.c

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1355,9 +1355,13 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
13551355
tok->lineno = the_current_tok->f_string_line_start;
13561356

13571357
if (current_tok->f_string_quote_size == 3) {
1358-
return MAKE_TOKEN(_PyTokenizer_syntaxerror(tok,
1358+
_PyTokenizer_syntaxerror(tok,
13591359
"unterminated triple-quoted f-string literal"
1360-
" (detected at line %d)", start));
1360+
" (detected at line %d)", start);
1361+
if (c != '\n') {
1362+
tok->done = E_EOFS;
1363+
}
1364+
return MAKE_TOKEN(ERRORTOKEN);
13611365
}
13621366
else {
13631367
return MAKE_TOKEN(_PyTokenizer_syntaxerror(tok,

0 commit comments

Comments
 (0)