From: Benjamin Peterson Date: Sat, 16 Aug 2008 22:11:33 +0000 (+0000) Subject: include filename and line number in SyntaxError X-Git-Tag: v2.6b3~66 X-Git-Url: http://git.ipfire.org/gitweb.cgi?a=commitdiff_plain;h=0847332716d538cc500f8495ddae81510d05b205;p=thirdparty%2FPython%2Fcpython.git include filename and line number in SyntaxError --- diff --git a/Lib/test/test_syntax.py b/Lib/test/test_syntax.py index 6e60706ac342..e978a6ec7a8f 100644 --- a/Lib/test/test_syntax.py +++ b/Lib/test/test_syntax.py @@ -5,7 +5,7 @@ Here's an example of the sort of thing that is tested. >>> def f(x): ... global x Traceback (most recent call last): -SyntaxError: name 'x' is local and global +SyntaxError: name 'x' is local and global (, line 1) The tests are all raise SyntaxErrors. They were created by checking each C call that raises SyntaxError. There are several modules that diff --git a/Python/symtable.c b/Python/symtable.c index cc3c774e6f6c..2f0b8897fb08 100644 --- a/Python/symtable.c +++ b/Python/symtable.c @@ -373,6 +373,9 @@ analyze_name(PySTEntryObject *ste, PyObject *dict, PyObject *name, long flags, PyErr_Format(PyExc_SyntaxError, "name '%s' is local and global", PyString_AS_STRING(name)); + PyErr_SyntaxLocation(ste->ste_table->st_filename, + ste->ste_lineno); + return 0; } SET_SCOPE(dict, name, GLOBAL_EXPLICIT);