[issue17413] format_exception() breask on exception tuples from trace function
Andreas Kloeckner
report at bugs.python.org
Thu Mar 14 01:56:34 CET 2013
New submission from Andreas Kloeckner:
traceback.format_exception() used to work properly with the 'arg' value passed to a tracing function set up via sys.settrace for an 'exception' event. In Python 3.x, this is no longer the case. Below you'll find what the attached test produces for a variety of interpreter versions.
If this is not intended to work, I would be much obliged for a hint on how to achieve the desired effect--i.e. get a formatted exception traceback for the exception tuple 'arg' passed to the trace function.
Thanks!
See also: https://github.com/inducer/pudb/issues/61
#####################################################
Python 2.7
#####################################################
ZZ call
ZZ line
ZZ line
ZZ exception
exception (<type 'exceptions.AttributeError'>, "'int' object has no attribute 'invalid'", <traceback object at 0x1951fc8>)
-------------------------------
Traceback (most recent call last):
File "exc-bug.py", line 20, in f
x.invalid
AttributeError: 'int' object has no attribute 'invalid'
-------------------------------
ZZ return
Traceback (most recent call last):
File "exc-bug.py", line 22, in <module>
f()
File "exc-bug.py", line 20, in f
x.invalid
AttributeError: 'int' object has no attribute 'invalid'
ZZ call
ZZ call
#####################################################
#####################################################
Python 3.2
#####################################################
ZZ call
ZZ line
ZZ line
ZZ exception
exception (<class 'AttributeError'>, "'int' object has no attribute 'invalid'", <traceback object at 0x7f4cf42e5f80>)
-------------------------------
Traceback (most recent call last):
File "exc-bug.py", line 22, in <module>
f()
File "exc-bug.py", line 20, in f
x.invalid
File "exc-bug.py", line 9, in trace
print("".join(format_exception(*arg)))
File "/usr/lib/python3.2/traceback.py", line 180, in format_exception
for value, tb in values:
File "/usr/lib/python3.2/traceback.py", line 122, in _iter_chain
cause = exc.__cause__
AttributeError: 'str' object has no attribute '__cause__'
#####################################################
#####################################################
Python 3.3
#####################################################
ZZ call
ZZ line
ZZ line
ZZ exception
exception (<class 'AttributeError'>, "'int' object has no attribute 'invalid'", <traceback object at 0x7f47383acb00>)
-------------------------------
Traceback (most recent call last):
File "exc-bug.py", line 22, in <module>
f()
File "exc-bug.py", line 20, in f
x.invalid
File "exc-bug.py", line 9, in trace
print("".join(format_exception(*arg)))
File "/usr/lib/python3.3/traceback.py", line 181, in format_exception
for value, tb in values:
File "/usr/lib/python3.3/traceback.py", line 122, in _iter_chain
context = exc.__context__
AttributeError: 'str' object has no attribute '__context__'
#####################################################
----------
components: Interpreter Core
files: exc-bug.py
messages: 184122
nosy: inducer
priority: normal
severity: normal
status: open
title: format_exception() breask on exception tuples from trace function
type: behavior
versions: Python 3.3
Added file: http://bugs.python.org/file29403/exc-bug.py
_______________________________________
Python tracker <report at bugs.python.org>
<http://bugs.python.org/issue17413>
_______________________________________
More information about the Python-bugs-list
mailing list