[issue29809] TypeError in traceback.print_exc - unicode does not have the buffer interface
Serhiy Storchaka
report at bugs.python.org
Tue Mar 14 11:36:23 EDT 2017
Serhiy Storchaka added the comment:
format_exception_only() produces a Unicode string for SyntaxError with Unicode source line.
>>> traceback.format_exception_only(SyntaxError, SyntaxError('failed', ('<tokenize>', 7, 2, u' // test')))
[' File "<tokenize>", line 7\n', u' // test\n', ' ^\n', 'SyntaxError: failed\n']
But io.BytesIO() accepts only binary strings.
The similar issue is caused by Unicode file name:
>>> traceback.format_exception_only(SyntaxError, SyntaxError('failed', (u'<tokenize>', 7, 2, ' // test')))
[u' File "<tokenize>", line 7\n', ' // test\n', ' ^\n', 'SyntaxError: failed\n']
But Unicode error message doesn't produce Unicode output:
>>> traceback.format_exception_only(SyntaxError, SyntaxError(u'failed', ('<tokenize>', 7, 2, ' // test')))
[' File "<tokenize>", line 7\n', ' // test\n', ' ^\n', 'SyntaxError: failed\n']
How you got a Unicode source line in SyntaxError?
----------
components: +Library (Lib), Unicode
nosy: +ezio.melotti, haypo, serhiy.storchaka
type: -> behavior
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue29809>
_______________________________________
More information about the Python-bugs-list
mailing list