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):
10751075 with self .assertRaisesRegex (ValueError , msg ):
10761076 ast .literal_eval (node )
10771077
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+
10781086 def test_bad_integer (self ):
10791087 # issue13436: Bad error message with invalid numeric values
10801088 body = [ast .ImportFrom (module = 'time' ,
Original file line number Diff line number Diff line change @@ -223,7 +223,7 @@ def testSyntaxErrorOffset(self):
223223 check ('x = "a' , 1 , 5 )
224224 check ('lambda x: x = 2' , 1 , 1 )
225225 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 )
227227 check ('a = « hello » « world »' , 1 , 5 )
228228 check ('[\n file\n for str(file)\n in\n []\n ]' , 3 , 5 )
229229 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)
13421342{
13431343 void * res = _PyPegen_parse (p );
13441344 if (res == NULL ) {
1345+ if (PyErr_Occurred () && !PyErr_ExceptionMatches (PyExc_SyntaxError )) {
1346+ return NULL ;
1347+ }
13451348 Token * last_token = p -> tokens [p -> fill - 1 ];
13461349 reset_parser_state (p );
13471350 _PyPegen_parse (p );
13481351 if (PyErr_Occurred ()) {
13491352 // Prioritize tokenizer errors to custom syntax errors raised
13501353 // 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 )) {
13521355 _PyPegen_check_tokenizer_errors (p );
13531356 }
13541357 return NULL ;
You can’t perform that action at this time.
0 commit comments