]> git.ipfire.org Git - thirdparty/Python/cpython.git/commitdiff
include filename and line number in SyntaxError
authorBenjamin Peterson <benjamin@python.org>
Sat, 16 Aug 2008 22:11:33 +0000 (22:11 +0000)
committerBenjamin Peterson <benjamin@python.org>
Sat, 16 Aug 2008 22:11:33 +0000 (22:11 +0000)
Lib/test/test_syntax.py
Python/symtable.c

index 6e60706ac342dd5a8e85237d966d30deeac2c5bf..e978a6ec7a8fd59743182a8e3e7b40e8a8d06ad2 100644 (file)
@@ -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 (<doctest test.test_syntax[0]>, line 1)
 
 The tests are all raise SyntaxErrors.  They were created by checking
 each C call that raises SyntaxError.  There are several modules that
index cc3c774e6f6c859ea16aaa12b079af6404e5d081..2f0b8897fb0872183ea641d4e86cc782e46e631a 100644 (file)
@@ -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);