File tree Expand file tree Collapse file tree 4 files changed +15
-2
lines changed
Misc/NEWS.d/next/Core and Builtins Expand file tree Collapse file tree 4 files changed +15
-2
lines changed Original file line number Diff line number Diff line change @@ -1044,6 +1044,14 @@ def test_literal_eval_malformed_lineno(self):
1044
1044
with self .assertRaisesRegex (ValueError , msg ):
1045
1045
ast .literal_eval (node )
1046
1046
1047
+ def test_literal_eval_syntax_errors (self ):
1048
+ msg = "unexpected character after line continuation character"
1049
+ with self .assertRaisesRegex (SyntaxError , msg ):
1050
+ ast .literal_eval (r'''
1051
+ \
1052
+ (\
1053
+ \ ''' )
1054
+
1047
1055
def test_bad_integer (self ):
1048
1056
# issue13436: Bad error message with invalid numeric values
1049
1057
body = [ast .ImportFrom (module = 'time' ,
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ def testSyntaxErrorOffset(self):
223
223
check ('x = "a' , 1 , 5 )
224
224
check ('lambda x: x = 2' , 1 , 1 )
225
225
check ('f{a + b + c}' , 1 , 2 )
226
- check ('[file for str(file) in []\n ])' , 2 , 2 )
226
+ check ('[file for str(file) in []\n ])' , 1 , 11 )
227
227
check ('a = « hello » « world »' , 1 , 5 )
228
228
check ('[\n file\n for str(file)\n in\n []\n ]' , 3 , 5 )
229
229
check ('[file for\n str(file) in []]' , 2 , 2 )
Original file line number Diff line number Diff line change
1
+ Fix a crash in the parser when reporting tokenizer errors that occur at the
2
+ same time unclosed parentheses are detected. Patch by Pablo Galindo.
Original file line number Diff line number Diff line change @@ -1321,13 +1321,16 @@ _PyPegen_run_parser(Parser *p)
1321
1321
{
1322
1322
void * res = _PyPegen_parse (p );
1323
1323
if (res == NULL ) {
1324
+ if (PyErr_Occurred () && !PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1325
+ return NULL ;
1326
+ }
1324
1327
Token * last_token = p -> tokens [p -> fill - 1 ];
1325
1328
reset_parser_state (p );
1326
1329
_PyPegen_parse (p );
1327
1330
if (PyErr_Occurred ()) {
1328
1331
// Prioritize tokenizer errors to custom syntax errors raised
1329
1332
// on the second phase only if the errors come from the parser.
1330
- if (p -> tok -> done != E_ERROR && PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1333
+ if (p -> tok -> done == E_DONE && PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1331
1334
_PyPegen_check_tokenizer_errors (p );
1332
1335
}
1333
1336
return NULL ;
You can’t perform that action at this time.
0 commit comments