mirror of
https://github.com/python/cpython.git
synced 2025-08-09 19:38:42 +00:00
[3.12] gh-113703: Correctly identify incomplete f-strings in the codeop module (GH-113709) (#113733)
(cherry picked from commit 3003fbbf00
)
This commit is contained in:
parent
8435fbfe4e
commit
0affc3d0f0
3 changed files with 12 additions and 3 deletions
|
@ -223,6 +223,9 @@ class CodeopTests(unittest.TestCase):
|
||||||
ai("(x for x in")
|
ai("(x for x in")
|
||||||
ai("(x for x in (")
|
ai("(x for x in (")
|
||||||
|
|
||||||
|
ai('a = f"""')
|
||||||
|
ai('a = \\')
|
||||||
|
|
||||||
def test_invalid(self):
|
def test_invalid(self):
|
||||||
ai = self.assertInvalid
|
ai = self.assertInvalid
|
||||||
ai("a b")
|
ai("a b")
|
||||||
|
|
|
@ -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
|
|
@ -2851,9 +2851,13 @@ f_string_middle:
|
||||||
tok->lineno = the_current_tok->f_string_line_start;
|
tok->lineno = the_current_tok->f_string_line_start;
|
||||||
|
|
||||||
if (current_tok->f_string_quote_size == 3) {
|
if (current_tok->f_string_quote_size == 3) {
|
||||||
return MAKE_TOKEN(syntaxerror(tok,
|
syntaxerror(tok,
|
||||||
"unterminated triple-quoted f-string literal"
|
"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 {
|
else {
|
||||||
return MAKE_TOKEN(syntaxerror(tok,
|
return MAKE_TOKEN(syntaxerror(tok,
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue