Skip to content
Merged
Show file tree
Hide file tree
Changes from 1 commit
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
3 changes: 3 additions & 0 deletions Lib/test/test_codeop.py
Original file line number Diff line number Diff line change
Expand Up @@ -223,6 +223,9 @@ def test_incomplete(self):
ai("(x for x in")
ai("(x for x in (")

ai('a = f"""')
ai('a = \\')

def test_invalid(self):
ai = self.assertInvalid
ai("a b")
Expand Down
Original file line number Diff line number Diff line change
@@ -0,0 +1,2 @@
Fix a regression in the :mod:`codeop` module that was causing to correctly
identify incomplete f-strings. Patch by Pablo Galindo
8 changes: 6 additions & 2 deletions Parser/lexer/lexer.c
Original file line number Diff line number Diff line change
Expand Up @@ -1355,9 +1355,13 @@ tok_get_fstring_mode(struct tok_state *tok, tokenizer_mode* current_tok, struct
tok->lineno = the_current_tok->f_string_line_start;

if (current_tok->f_string_quote_size == 3) {
return MAKE_TOKEN(_PyTokenizer_syntaxerror(tok,
_PyTokenizer_syntaxerror(tok,
"unterminated triple-quoted f-string literal"
" (detected at line %d)", start));
" (detected at line %d)", start);
if (c != '\n') {
tok->done = E_EOFS;
}
return MAKE_TOKEN(ERRORTOKEN);
}
else {
return MAKE_TOKEN(_PyTokenizer_syntaxerror(tok,
Expand Down