@@ -4548,6 +4548,16 @@ symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste,
45484548 return 0 ;
45494549}
45504550
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+
45514561static int
45524562symtable_load_symbols (struct compiling * c )
45534563{
@@ -4612,9 +4622,7 @@ symtable_load_symbols(struct compiling *c)
46124622 if (flags & DEF_PARAM ) {
46134623 PyErr_Format (PyExc_SyntaxError , LOCAL_GLOBAL ,
46144624 PyString_AS_STRING (name ));
4615- PyErr_SyntaxLocation (st -> st_filename ,
4616- ste -> ste_lineno );
4617- st -> st_errors ++ ;
4625+ symtable_error (st , 0 );
46184626 goto fail ;
46194627 }
46204628 if (PyDict_SetItem (c -> c_globals , name , Py_None ) < 0 )
@@ -4959,9 +4967,7 @@ symtable_add_def_o(struct symtable *st, PyObject *dict,
49594967 if ((flag & DEF_PARAM ) && (val & DEF_PARAM )) {
49604968 PyErr_Format (PyExc_SyntaxError , DUPLICATE_ARGUMENT ,
49614969 PyString_AsString (name ));
4962- PyErr_SyntaxLocation (st -> st_filename ,
4963- st -> st_cur -> ste_lineno );
4964- return -1 ;
4970+ return symtable_error (st , 0 );
49654971 }
49664972 val |= flag ;
49674973 } else
@@ -5358,9 +5364,7 @@ symtable_global(struct symtable *st, node *n)
53585364 PyErr_Format (PyExc_SyntaxError ,
53595365 "name '%.400s' is local and global" ,
53605366 name );
5361- PyErr_SyntaxLocation (st -> st_filename ,
5362- st -> st_cur -> ste_lineno );
5363- st -> st_errors ++ ;
5367+ symtable_error (st , 0 );
53645368 return ;
53655369 }
53665370 else {
@@ -5420,9 +5424,7 @@ symtable_import(struct symtable *st, node *n)
54205424 if (n -> n_lineno >= st -> st_future -> ff_last_lineno ) {
54215425 PyErr_SetString (PyExc_SyntaxError ,
54225426 LATE_FUTURE );
5423- PyErr_SyntaxLocation (st -> st_filename ,
5424- n -> n_lineno );
5425- st -> st_errors ++ ;
5427+ symtable_error (st , n -> n_lineno );
54265428 return ;
54275429 }
54285430 }
@@ -5515,9 +5517,8 @@ symtable_assign(struct symtable *st, node *n, int def_flag)
55155517 if (strcmp (STR (tmp ), "__debug__" ) == 0 ) {
55165518 PyErr_SetString (PyExc_SyntaxError ,
55175519 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 ;
55215522 }
55225523 symtable_add_def (st , STR (tmp ), DEF_LOCAL | def_flag );
55235524 }
0 commit comments