Author inducer
Recipients inducer
Date 2013-03-14.00:56:34
SpamBayes Score -1.0
Marked as misclassified Yes
Message-id <1363222594.63.0.566610526845.issue17413@psf.upfronthosting.co.za>
In-reply-to
Content
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__'
#####################################################
History
Date User Action Args
2013-03-14 00:56:34inducersetrecipients: + inducer
2013-03-14 00:56:34inducersetmessageid: <1363222594.63.0.566610526845.issue17413@psf.upfronthosting.co.za>
2013-03-14 00:56:34inducerlinkissue17413 messages
2013-03-14 00:56:34inducercreate