include filename and line number in SyntaxError

This commit is contained in:
Benjamin Peterson 2008-08-16 22:11:33 +00:00
parent 721b1457a0
commit 0847332716
2 changed files with 4 additions and 1 deletions

View file

@ -5,7 +5,7 @@ Here's an example of the sort of thing that is tested.
>>> def f(x): >>> def f(x):
... global x ... global x
Traceback (most recent call last): Traceback (most recent call last):
SyntaxError: name 'x' is local and global SyntaxError: name 'x' is local and global (<doctest test.test_syntax[0]>, line 1)
The tests are all raise SyntaxErrors. They were created by checking The tests are all raise SyntaxErrors. They were created by checking
each C call that raises SyntaxError. There are several modules that each C call that raises SyntaxError. There are several modules that

View file

@ -373,6 +373,9 @@ analyze_name(PySTEntryObject *ste, PyObject *dict, PyObject *name, long flags,
PyErr_Format(PyExc_SyntaxError, PyErr_Format(PyExc_SyntaxError,
"name '%s' is local and global", "name '%s' is local and global",
PyString_AS_STRING(name)); PyString_AS_STRING(name));
PyErr_SyntaxLocation(ste->ste_table->st_filename,
ste->ste_lineno);
return 0; return 0;
} }
SET_SCOPE(dict, name, GLOBAL_EXPLICIT); SET_SCOPE(dict, name, GLOBAL_EXPLICIT);