Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[3.12] gh-113703: Correctly identify incomplete f-strings in the codeop module (GH-113709) #113733

Merged
merged 1 commit into from
Jan 5, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
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 it to incorrectly
identify incomplete f-strings. Patch by Pablo Galindo
10 changes: 7 additions & 3 deletions Parser/tokenizer.c
Original file line number Diff line number Diff line change
Expand Up @@ -2851,9 +2851,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(syntaxerror(tok,
"unterminated triple-quoted f-string literal"
" (detected at line %d)", start));
syntaxerror(tok,
"unterminated triple-quoted f-string literal"
" (detected at line %d)", start);
if (c != '\n') {
tok->done = E_EOFS;
}
return MAKE_TOKEN(ERRORTOKEN);
}
else {
return MAKE_TOKEN(syntaxerror(tok,
Expand Down