Skip to content

Commit e54c960

Browse files
author
benjamin.peterson
committed
include filename and line number in SyntaxError
git-svn-id: http://svn.python.org/projects/python/trunk@65724 6015fed2-1504-0410-9fe1-9d1591cc4771
1 parent 2c908cd commit e54c960

2 files changed

Lines changed: 4 additions & 1 deletion

File tree

Lib/test/test_syntax.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,7 @@
55
>>> def f(x):
66
... global x
77
Traceback (most recent call last):
8-
SyntaxError: name 'x' is local and global
8+
SyntaxError: name 'x' is local and global (<doctest test.test_syntax[0]>, line 1)
99
1010
The tests are all raise SyntaxErrors. They were created by checking
1111
each C call that raises SyntaxError. There are several modules that

Python/symtable.c

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -373,6 +373,9 @@ analyze_name(PySTEntryObject *ste, PyObject *dict, PyObject *name, long flags,
373373
PyErr_Format(PyExc_SyntaxError,
374374
"name '%s' is local and global",
375375
PyString_AS_STRING(name));
376+
PyErr_SyntaxLocation(ste->ste_table->st_filename,
377+
ste->ste_lineno);
378+
376379
return 0;
377380
}
378381
SET_SCOPE(dict, name, GLOBAL_EXPLICIT);

0 commit comments

Comments
 (0)