mirror of
https://github.com/python/cpython.git
synced 2025-08-03 16:39:00 +00:00
bpo-43822: Prioritize tokenizer errors over custom syntax errors when raising parser exceptions (GH-25866)
(cherry picked from commit 9142088e74
)
Co-authored-by: Pablo Galindo <Pablogsal@gmail.com>
This commit is contained in:
parent
4d58730a3a
commit
756b7b9248
3 changed files with 6 additions and 1 deletions
|
@ -210,7 +210,7 @@ class ExceptionTests(unittest.TestCase):
|
||||||
check('x = "a', 1, 5)
|
check('x = "a', 1, 5)
|
||||||
check('lambda x: x = 2', 1, 1)
|
check('lambda x: x = 2', 1, 1)
|
||||||
check('f{a + b + c}', 1, 2)
|
check('f{a + b + c}', 1, 2)
|
||||||
check('[file for str(file) in []\n])', 1, 11)
|
check('[file for str(file) in []\n])', 2, 2)
|
||||||
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
|
check('[\nfile\nfor str(file)\nin\n[]\n]', 3, 5)
|
||||||
check('[file for\n str(file) in []]', 2, 2)
|
check('[file for\n str(file) in []]', 2, 2)
|
||||||
|
|
||||||
|
|
|
@ -0,0 +1,2 @@
|
||||||
|
The parser will prioritize tokenizer errors over custom syntax errors when
|
||||||
|
raising exceptions. Patch by Pablo Galindo.
|
|
@ -1283,6 +1283,9 @@ _PyPegen_run_parser(Parser *p)
|
||||||
reset_parser_state(p);
|
reset_parser_state(p);
|
||||||
_PyPegen_parse(p);
|
_PyPegen_parse(p);
|
||||||
if (PyErr_Occurred()) {
|
if (PyErr_Occurred()) {
|
||||||
|
if (PyErr_ExceptionMatches(PyExc_SyntaxError)) {
|
||||||
|
_PyPegen_check_tokenizer_errors(p);
|
||||||
|
}
|
||||||
return NULL;
|
return NULL;
|
||||||
}
|
}
|
||||||
if (p->fill == 0) {
|
if (p->fill == 0) {
|
||||||
|
|
Loading…
Add table
Add a link
Reference in a new issue