[issue3684] traceback.format_exception_only() misplaces the caret for certain SyntaxErrors
Brodie Rao
report at bugs.python.org
Tue Aug 26 04:30:26 CEST 2008
New submission from Brodie Rao <junk at dackz.net>:
>> +
File "<stdin>", line 1
+
^
SyntaxError: invalid syntax
>>> import sys
>>> import traceback
>>> traceback.print_exception(sys.last_type, sys.last_value, None)
File "<stdin>", line 1
+
^
SyntaxError: invalid syntax
>>> sys.last_value
SyntaxError('invalid syntax', ('<stdin>', 1, 2, '+\n'))
print_error_text() effectively ignores trailing newlines when placing
the caret, while traceback.format_exception_only() does not. For certain
syntax errors the offset reported is sometimes at the newline, as in the
case of a line of code that ends just with a plus sign (and in other
similar cases).
I'm attaching a patch for trunk that fixes this issue. I know it also
affects Python 2.5, and I'm sure it affects versions prior. I don't know
about Python 3.0.
----------
components: Library (Lib)
files: traceback-caret.patch
keywords: patch
messages: 71967
nosy: brodierao
severity: normal
status: open
title: traceback.format_exception_only() misplaces the caret for certain SyntaxErrors
type: behavior
Added file: http://bugs.python.org/file11260/traceback-caret.patch
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue3684>
_______________________________________
More information about the Python-bugs-list
mailing list