@@ -4777,6 +4777,16 @@ symtable_update_flags(struct compiling *c, PySymtableEntryObject *ste,
47774777 return 0 ;
47784778}
47794779
4780+ static int
4781+ symtable_error (struct symtable * st , int lineno )
4782+ {
4783+ if (lineno == 0 )
4784+ lineno = st -> st_cur -> ste_lineno ;
4785+ PyErr_SyntaxLocation (st -> st_filename , lineno );
4786+ st -> st_errors ++ ;
4787+ return -1 ;
4788+ }
4789+
47804790static int
47814791symtable_load_symbols (struct compiling * c )
47824792{
@@ -4835,9 +4845,7 @@ symtable_load_symbols(struct compiling *c)
48354845 if (flags & DEF_PARAM ) {
48364846 PyErr_Format (PyExc_SyntaxError , LOCAL_GLOBAL ,
48374847 PyString_AS_STRING (name ));
4838- PyErr_SyntaxLocation (st -> st_filename ,
4839- ste -> ste_lineno );
4840- st -> st_errors ++ ;
4848+ symtable_error (st , 0 );
48414849 goto fail ;
48424850 }
48434851 if (PyDict_SetItem (c -> c_globals , name , Py_None ) < 0 )
@@ -5190,9 +5198,7 @@ symtable_add_def_o(struct symtable *st, PyObject *dict,
51905198 if ((flag & DEF_PARAM ) && (val & DEF_PARAM )) {
51915199 PyErr_Format (PyExc_SyntaxError , DUPLICATE_ARGUMENT ,
51925200 PyString_AsString (name ));
5193- PyErr_SyntaxLocation (st -> st_filename ,
5194- st -> st_cur -> ste_lineno );
5195- return -1 ;
5201+ return symtable_error (st , 0 );
51965202 }
51975203 val |= flag ;
51985204 } else
@@ -5589,9 +5595,7 @@ symtable_global(struct symtable *st, node *n)
55895595 PyErr_Format (PyExc_SyntaxError ,
55905596 "name '%.400s' is local and global" ,
55915597 name );
5592- PyErr_SyntaxLocation (st -> st_filename ,
5593- st -> st_cur -> ste_lineno );
5594- st -> st_errors ++ ;
5598+ symtable_error (st , 0 );
55955599 return ;
55965600 }
55975601 else {
@@ -5651,9 +5655,7 @@ symtable_import(struct symtable *st, node *n)
56515655 if (n -> n_lineno >= st -> st_future -> ff_last_lineno ) {
56525656 PyErr_SetString (PyExc_SyntaxError ,
56535657 LATE_FUTURE );
5654- PyErr_SyntaxLocation (st -> st_filename ,
5655- n -> n_lineno );
5656- st -> st_errors ++ ;
5658+ symtable_error (st , n -> n_lineno );
56575659 return ;
56585660 }
56595661 }
@@ -5747,9 +5749,8 @@ symtable_assign(struct symtable *st, node *n, int def_flag)
57475749 if (strcmp (STR (tmp ), "__debug__" ) == 0 ) {
57485750 PyErr_SetString (PyExc_SyntaxError ,
57495751 ASSIGN_DEBUG );
5750- PyErr_SyntaxLocation (st -> st_filename ,
5751- n -> n_lineno );
5752- st -> st_errors ++ ;
5752+ symtable_error (st , n -> n_lineno );
5753+ return ;
57535754 }
57545755 symtable_add_def (st , STR (tmp ), DEF_LOCAL | def_flag );
57555756 }
0 commit comments