Thanks to visit codestin.com
Credit goes to github.com

Skip to content

Commit 9142088

Browse files
authored
bpo-43822: Prioritize tokenizer errors over custom syntax errors when raising parser exceptions (GH-25866)
1 parent 0aaf13a commit 9142088

3 files changed

Lines changed: 6 additions & 1 deletion

File tree

Lib/test/test_exceptions.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -210,7 +210,7 @@ def testSyntaxErrorOffset(self):
210210
check('x = "a', 1, 5)
211211
check('lambda x: x = 2', 1, 1)
212212
check('f{a + b + c}', 1, 2)
213-
check('[file for str(file) in []\n])', 1, 11)
213+
check('[file for str(file) in []\n])', 2, 2)
214214
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
215215
check('[file for\n str(file) in []]', 2, 2)
216216

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,2 @@
1+
The parser will prioritize tokenizer errors over custom syntax errors when
2+
raising exceptions. Patch by Pablo Galindo.

Parser/pegen.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1283,6 +1283,9 @@ _PyPegen_run_parser(Parser *p)
12831283
reset_parser_state(p);
12841284
_PyPegen_parse(p);
12851285
if (PyErr_Occurred()) {
1286+
if (PyErr_ExceptionMatches(PyExc_SyntaxError)) {
1287+
_PyPegen_check_tokenizer_errors(p);
1288+
}
12861289
return NULL;
12871290
}
12881291
if (p->fill == 0) {

0 commit comments

Comments
 (0)