Issue #79 resolved

six.reraise raises different traceback than provided

Tomas Radej
created an issue

When I raise an exception via six.reraise and provide a particular traceback, the collected traceback in the subsequent except block doesn't match (it includes the reraise in it). See the attached reproducer. I would expect either to get exactly the same traceback as I assigned, or the documentation stating explicitly that the traceback will not be identical.

import six
import sys

class Exception1(Exception):
    pass

class Exception2(Exception):
    pass

# Old way
try:
    raise Exception1, (1, 'Reason1')
except Exception1 as e1:
    traceback = sys.exc_info()[2]
    try:
        raise Exception2, e1, traceback # Important line
    except Exception2:
        assert traceback == sys.exc_info()[2]

# New way
try:
    raise Exception1(1, 'Reason1')
except Exception1:
    exc_type, exc, traceback = sys.exc_info()
    try:
        six.reraise(Exception2, exc, traceback) # Important line
    except Exception2:
        assert traceback == sys.exc_info()[2]

Comments (4)

  1. Log in to comment