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 @@ -1075,6 +1075,14 @@ def test_literal_eval_malformed_lineno(self):
1075
1075
with self .assertRaisesRegex (ValueError , msg ):
1076
1076
ast .literal_eval (node )
1077
1077
1078
+ def test_literal_eval_syntax_errors (self ):
1079
+ msg = "unexpected character after line continuation character"
1080
+ with self .assertRaisesRegex (SyntaxError , msg ):
1081
+ ast .literal_eval (r'''
1082
+ \
1083
+ (\
1084
+ \ ''' )
1085
+
1078
1086
def test_bad_integer (self ):
1079
1087
# issue13436: Bad error message with invalid numeric values
1080
1088
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 , 1 )
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 @@ -1342,13 +1342,16 @@ _PyPegen_run_parser(Parser *p)
1342
1342
{
1343
1343
void * res = _PyPegen_parse (p );
1344
1344
if (res == NULL ) {
1345
+ if (PyErr_Occurred () && !PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1346
+ return NULL ;
1347
+ }
1345
1348
Token * last_token = p -> tokens [p -> fill - 1 ];
1346
1349
reset_parser_state (p );
1347
1350
_PyPegen_parse (p );
1348
1351
if (PyErr_Occurred ()) {
1349
1352
// Prioritize tokenizer errors to custom syntax errors raised
1350
1353
// on the second phase only if the errors come from the parser.
1351
- if (p -> tok -> done != E_ERROR && PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1354
+ if (p -> tok -> done == E_DONE && PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1352
1355
_PyPegen_check_tokenizer_errors (p );
1353
1356
}
1354
1357
return NULL ;
You can’t perform that action at this time.
0 commit comments