8000 bpo-44335: Fix a regression when identifying invalid characters in sy… · python/cpython@933b5b6 · GitHub
[go: up one dir, main page]

Skip to content

Commit 933b5b6

Browse files
bpo-44335: Fix a regression when identifying invalid characters in syntax errors (GH-26589)
(cherry picked from commit d334c73) Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
1 parent d80f426 commit 933b5b6

File tree

3 files changed

+6
-1
lines changed

3 files changed

+6
-1
lines changed

Lib/test/test_exceptions.py

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -211,6 +211,7 @@ def testSyntaxErrorOffset(self):
211211
check('lambda x: x = 2', 1, 1)
212212
check('f{a + b + c}', 1, 2)
213213
check('[file for str(file) in []\n])', 2, 2)
214+
check('a = « hello » « world »', 1, 5)
214215
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
215216
check('[file for\n str(file) in []]', 2, 2)
216217
check("ages = {'Alice'=22, 'Bob'=23}", 1, 16)
Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
Fix a regression when identifying incorrect characters in syntax errors.
2+
Patch by Pablo Galindo

Parser/pegen.c

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1288,7 +1288,9 @@ _PyPegen_run_parser(Parser *p)
12881288
reset_parser_state(p);
12891289
_PyPegen_parse(p);
12901290
if (PyErr_Occurred()) {
1291-
if (PyErr_ExceptionMatches(PyExc_SyntaxError)) {
1291+
// Prioritize tokenizer errors to custom syntax errors raised
1292+
// on the second phase only if the errors come from the parser.
1293+
if (p->tok->done != E_ERROR && PyErr_ExceptionMatches(PyExc_SyntaxError)) {
12921294
_PyPegen_check_tokenizer_errors(p);
12931295
}
12941296
return NULL;

0 commit comments

Comments
 (0)
0