Skip to content
Snippets Groups Projects
Commit 34b2d7e0 authored by Piotr Maślanka's avatar Piotr Maślanka
Browse files

Traceback() may accept an Exception instance

parent 3ffcaa63
No related branches found
Tags 2.26.6
No related merge requests found
Pipeline #64245 passed with stages
in 2 minutes and 5 seconds
# v2.26.6
* _TBA_
* Traceback() may accept an Exception instance
# v2.26.5
......
__version__ = '2.26.6a1'
__version__ = '2.26.6'
......@@ -53,7 +53,7 @@ class Traceback(JSONAble):
out.append(str(frame))
return ''.join(out)
def __init__(self, starting_frame: tp.Optional[types.FrameType] = None,
def __init__(self, starting_frame: tp.Optional[tp.Union[Exception, types.FrameType]] = None,
policy=GenerationPolicy):
if inspect.isclass(policy):
value_pickling_policy = policy()
......@@ -69,7 +69,10 @@ class Traceback(JSONAble):
else:
f = inspect.currentframe()
else:
f = starting_frame
if isinstance(starting_frame, Exception):
f = starting_frame.__traceback__.tb_frame
else:
f = starting_frame
while f:
self.frames.append(StackFrame(f, value_pickling_policy))
......
......@@ -7,6 +7,14 @@ from satella.instrumentation import Traceback, get_current_traceback
class TestTraceback(unittest.TestCase):
def test_traceback_from_exception(self):
try:
a = 1 / 0
except ZeroDivisionError as e:
tb = Traceback(e)
self.assertIn('ZeroDivisionError', tb.pretty_format())
def test_get_current_traceback(self):
try:
a = 1 / 0
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment