Index: Python/traceback.c =================================================================== --- Python/traceback.c (revision 64854) +++ Python/traceback.c (working copy) @@ -123,7 +123,7 @@ } int -Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno) +Py_DisplaySourceLine(PyObject *f, const char *filename, int lineno, int indent) { int err = 0; FILE *xfp = NULL; @@ -197,12 +197,27 @@ } while (*pLastChar != '\0' && *pLastChar != '\n'); } if (i == lineno) { + char buf[11]; char *p = linebuf; while (*p == ' ' || *p == '\t' || *p == '\014') p++; - err = PyFile_WriteString(p, f); - if (err == 0 && strchr(p, '\n') == NULL) - err = PyFile_WriteString("\n", f); + + /* Write some spaces before the line */ + strcpy(buf, " "); + assert (strlen(buf) == 10); + while (indent > 0) { + if(indent < 10) + buf[indent] = '\0'; + err = PyFile_WriteString(buf, f); + if (err != 0) + break; + indent -= 10; + } + + if (err == 0) + err = PyFile_WriteString(p, f); + if (err == 0 && strchr(p, '\n') == NULL) + err = PyFile_WriteString("\n", f); } fclose(xfp); return err; @@ -222,7 +237,7 @@ err = PyFile_WriteString(linebuf, f); if (err != 0) return err; - return Py_DisplaySourceLine(f, filename, lineno); + return Py_DisplaySourceLine(f, filename, lineno, 4); } static int Index: Python/_warnings.c =================================================================== --- Python/_warnings.c (revision 64854) +++ Python/_warnings.c (working copy) @@ -256,7 +256,6 @@ Py_XDECREF(name); /* Print " source_line\n" */ - PyFile_WriteString(" ", f_stderr); if (sourceline) { char *source_line_str = PyString_AS_STRING(sourceline); while (*source_line_str == ' ' || *source_line_str == '\t' || @@ -267,7 +266,7 @@ PyFile_WriteString("\n", f_stderr); } else - Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename), lineno); + Py_DisplaySourceLine(f_stderr, PyString_AS_STRING(filename), lineno, 2); PyErr_Clear(); } Index: Include/traceback.h =================================================================== --- Include/traceback.h (revision 64854) +++ Include/traceback.h (working copy) @@ -19,7 +19,7 @@ PyAPI_FUNC(int) PyTraceBack_Here(struct _frame *); PyAPI_FUNC(int) PyTraceBack_Print(PyObject *, PyObject *); -PyAPI_FUNC(int) Py_DisplaySourceLine(PyObject *, const char *, int); +PyAPI_FUNC(int) Py_DisplaySourceLine(PyObject *, const char *, int, int); /* Reveal traceback type so we can typecheck traceback objects */ PyAPI_DATA(PyTypeObject) PyTraceBack_Type; Index: Lib/test/test_traceback.py =================================================================== --- Lib/test/test_traceback.py (revision 64854) +++ Lib/test/test_traceback.py (working copy) @@ -177,7 +177,7 @@ banner, location, source_line = tb_lines self.assert_(banner.startswith('Traceback')) self.assert_(location.startswith(' File')) - self.assert_(source_line.startswith('raise')) + self.assert_(source_line.startswith(' raise')) def test_main():