https://github.com/python/cpython/commit/0affc3d0f070f1fef4da915ba560875c7bcec7bb
commit: 0affc3d0f070f1fef4da915ba560875c7bcec7bb
branch: 3.12
author: Pablo Galindo Salgado <[email protected]>
committer: pablogsal <[email protected]>
date: 2024-01-05T13:23:40Z
summary:
[3.12] gh-113703: Correctly identify incomplete f-strings in the codeop module
(GH-113709) (#113733)
(cherry picked from commit 3003fbbf00422bce6e327646063e97470afa9091)
files:
A Misc/NEWS.d/next/Core and
Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst
M Lib/test/test_codeop.py
M Parser/tokenizer.c
diff --git a/Lib/test/test_codeop.py b/Lib/test/test_codeop.py
index 2abb6c6d935b7e..787bd1b6a79e20 100644
--- a/Lib/test/test_codeop.py
+++ b/Lib/test/test_codeop.py
@@ -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")
diff --git a/Misc/NEWS.d/next/Core and
Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst b/Misc/NEWS.d/next/Core
and Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst
new file mode 100644
index 00000000000000..5db93e344724fb
--- /dev/null
+++ b/Misc/NEWS.d/next/Core and
Builtins/2024-01-04-17-15-30.gh-issue-113703.Zsk0pY.rst
@@ -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
diff --git a/Parser/tokenizer.c b/Parser/tokenizer.c
index d2f967d35ac4b3..04ba04428fef62 100644
--- a/Parser/tokenizer.c
+++ b/Parser/tokenizer.c
@@ -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,
_______________________________________________
Python-checkins mailing list -- [email protected]
To unsubscribe send an email to [email protected]
https://mail.python.org/mailman3/lists/python-checkins.python.org/
Member address: [email protected]