@@ -4548,6 +4548,16 @@ symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste,
4548
4548
return 0 ;
4549
4549
}
4550
4550
4551
+ static int
4552
+ symtable_error (struct symtable * st , int lineno )
4553
+ {
4554
+ if (lineno == 0 )
4555
+ lineno = st -> st_cur -> ste_lineno ;
4556
+ PyErr_SyntaxLocation (st -> st_filename , lineno );
4557
+ st -> st_errors ++ ;
4558
+ return -1 ;
4559
+ }
4560
+
4551
4561
static int
4552
4562
symtable_load_symbols (struct compiling * c )
4553
4563
{
@@ -4612,9 +4622,7 @@ symtable_load_symbols(struct compiling *c)
4612
4622
if (flags & DEF_PARAM ) {
4613
4623
PyErr_Format (PyExc_SyntaxError , LOCAL_GLOBAL ,
4614
4624
PyString_AS_STRING (name ));
4615
- PyErr_SyntaxLocation (st -> st_filename ,
4616
- ste -> ste_lineno );
4617
- st -> st_errors ++ ;
4625
+ symtable_error (st , 0 );
4618
4626
goto fail ;
4619
4627
}
4620
4628
if (PyDict_SetItem (c -> c_globals , name , Py_None ) < 0 )
@@ -4959,9 +4967,7 @@ symtable_add_def_o(struct symtable *st, PyObject *dict,
4959
4967
if ((flag & DEF_PARAM ) && (val & DEF_PARAM )) {
4960
4968
PyErr_Format (PyExc_SyntaxError , DUPLICATE_ARGUMENT ,
4961
4969
PyString_AsString (name ));
4962
- PyErr_SyntaxLocation (st -> st_filename ,
4963
- st -> st_cur -> ste_lineno );
4964
- return -1 ;
4970
+ return symtable_error (st , 0 );
4965
4971
}
4966
4972
val |= flag ;
4967
4973
} else
@@ -5358,9 +5364,7 @@ symtable_global(struct symtable *st, node *n)
5358
5364
PyErr_Format (PyExc_SyntaxError ,
5359
5365
"name '%.400s' is local and global" ,
5360
5366
name );
5361
- PyErr_SyntaxLocation (st -> st_filename ,
5362
- st -> st_cur -> ste_lineno );
5363
- st -> st_errors ++ ;
5367
+ symtable_error (st , 0 );
5364
5368
return ;
5365
5369
}
5366
5370
else {
@@ -5420,9 +5424,7 @@ symtable_import(struct symtable *st, node *n)
5420
5424
if (n -> n_lineno >= st -> st_future -> ff_last_lineno ) {
5421
5425
PyErr_SetString (PyExc_SyntaxError ,
5422
5426
LATE_FUTURE );
5423
- PyErr_SyntaxLocation (st -> st_filename ,
5424
- n -> n_lineno );
5425
- st -> st_errors ++ ;
5427
+ symtable_error (st , n -> n_lineno );
5426
5428
return ;
5427
5429
}
5428
5430
}
@@ -5515,9 +5517,8 @@ symtable_assign(struct symtable *st, node *n, int def_flag)
5515
5517
if (strcmp (STR (tmp ), "__debug__" ) == 0 ) {
5516
5518
PyErr_SetString (PyExc_SyntaxError ,
5517
5519
ASSIGN_DEBUG );
5518
- PyErr_SyntaxLocation (st -> st_filename ,
5519
- n -> n_lineno );
5520
- st -> st_errors ++ ;
5520
+ symtable_error (st , n -> n_lineno );
5521
+ return ;
5521
5522
}
5522
5523
symtable_add_def (st , STR (tmp ), DEF_LOCAL | def_flag );
5523
5524
}
0 commit comments