8000 [3.10] bpo-46240: Correct the error for unclosed parentheses when the… · python/cpython@633db1c · GitHub
[go: up one dir, main page]

Skip to content

Commit 633db1c

Browse files
authored
[3.10] bpo-46240: Correct the error for unclosed parentheses when the tokenizer is not finished (GH-30378). (GH-30819)
(cherry picked from commit 70f415f) Co-authored-by: Pablo Galindo Salgado <Pablogsal@gmail.com>
1 parent f66ef3e commit 633db1c

File tree

4 files changed

+9
-2
lines changed
  • Lib/test
  • Misc/NEWS.d/next/Core and Builtins
    • < 8000 a class="fgColor-default prc-Link-Link-85e08" data-muted="true" href="#diff-175e8a9e8a6447a80a42d8f87f5e819dae4f6a1ab28ee148ada006cbbe5b4d43" muted="" role="presentation" tabindex="-1">2022-01-03-23-31-25.bpo-46240.8lGjeK.rst
  • Parser

4 files changed

+9
-2
lines changed

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -227,7 +227,7 @@ def testSyntaxErrorOffset(self):
227227
check('x = "a', 1, 5)
228228
check('lambda x: x = 2', 1, 1)
229229
check('f{a + b + c}', 1, 2)
230-
check('[file for str(file) in []\n])', 1, 11)
230+
check('[file for str(file) in []\n]', 1, 11)
231231
check('a = « hello » « world »', 1, 5)
232232
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
233233
check('[file for\n str(file) in []]', 2, 2)

Lib/test/test_syntax.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1513,6 +1513,9 @@ def test_error_parenthesis(self):
15131513
for paren in "([{":
15141514
self._check_error(paren + "1 + 2", f"\\{paren}' was never closed")
15151515

1516+
for paren in "([{":
1517+
self._check_error(f"a = {paren} 1, 2, 3\nb=3", f"\\{paren}' was never closed")
1518+
15161519
for paren in ")]}":
15171520
self._check_error(paren + "1 + 2", f"unmatched '\\{paren}'")
15181521

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,3 @@
1+
Correct the error message for unclosed parentheses when the tokenizer
2+
doesn't reach the end of the source when the error is reported. Patch by
3+
Pablo Galindo

Parser/pegen.c

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1342,7 +1342,8 @@ _PyPegen_run_parser(Parser *p)
13421342
if (PyErr_Occurred()) {
13431343
// Prioritize tokenizer errors to custom syntax errors raised
13441344
// on the second phase only if the errors come from the parser.
1345-
if (p->tok->done == E_DONE && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
1345+
int is_tok_ok = (p->tok->done == E_DONE || p->tok->done == E_OK);
1346+
if (is_tok_ok && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
13461347
_PyPegen_check_tokenizer_errors(p);
13471348
}
13481349
return NULL;

0 commit comments

Comments
 (0)
0