Skip to content

Commit a9e76bf

Browse files
pablogsalGlyphack
authored andcommitted
pythongh-113703: Correctly identify incomplete f-strings in the codeop module (python#113709)
1 parent 1784a22 commit a9e76bf

File tree

3 files changed

+11
-2
lines changed

3 files changed

+11
-2
lines changed

Lib/test/test_codeop.py

+3
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")
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

+6-2
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)