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

added frame_from_traceback

parent 90c0380e
No related branches found
No related tags found
No related merge requests found
# v2.14.11 # v2.14.11
* added `frame_from_traceback`
...@@ -56,3 +56,7 @@ Alternatively, you can pass a `<frame>` object to Traceback, in order to seriali ...@@ -56,3 +56,7 @@ Alternatively, you can pass a `<frame>` object to Traceback, in order to seriali
.. autoclass:: satella.instrumentation.GenerationPolicy .. autoclass:: satella.instrumentation.GenerationPolicy
:members: :members:
There's a helper function as well
.. autofunction:: satella.instrumentation.frame_from_traceback
__version__ = '2.14.11_a1' __version__ = '2.14.11'
from .dump_frames_on import install_dump_frames_on from .dump_frames_on import install_dump_frames_on
from .trace_back import Traceback, GenerationPolicy, StackFrame, StoredVariableValue from .trace_back import Traceback, GenerationPolicy, StackFrame, StoredVariableValue, \
frame_from_traceback
__all__ = ['install_dump_frames_on', 'Traceback', 'GenerationPolicy', 'StoredVariableValue', __all__ = ['install_dump_frames_on', 'Traceback', 'GenerationPolicy', 'StoredVariableValue',
'StackFrame'] 'StackFrame', 'frame_from_traceback']
from .classes import GenerationPolicy, StackFrame, StoredVariableValue from .classes import GenerationPolicy, StackFrame, StoredVariableValue
from .trace_back import Traceback from .trace_back import Traceback, frame_from_traceback
__all__ = ['GenerationPolicy', 'StoredVariableValue', 'StackFrame', 'Traceback'] __all__ = ['GenerationPolicy', 'StoredVariableValue', 'StackFrame', 'Traceback',
'frame_from_traceback']
...@@ -15,6 +15,18 @@ from satella.json import JSONAble ...@@ -15,6 +15,18 @@ from satella.json import JSONAble
from .classes import StackFrame, GenerationPolicy from .classes import StackFrame, GenerationPolicy
def frame_from_traceback(tb: types.TracebackType) -> types.FrameType:
"""
Extract the bottom stack frame from a traceback
:param tb: traceback to extract the frame
:return: bottom stack frame
"""
while tb.tb_next:
tb = tb.tb_next
return tb.tb_frame
class Traceback(JSONAble): class Traceback(JSONAble):
""" """
Class used to preserve exceptions and chains of stack frames. Class used to preserve exceptions and chains of stack frames.
...@@ -53,9 +65,7 @@ class Traceback(JSONAble): ...@@ -53,9 +65,7 @@ class Traceback(JSONAble):
if starting_frame is None: if starting_frame is None:
tb = sys.exc_info()[2] tb = sys.exc_info()[2]
if tb is not None: if tb is not None:
while tb.tb_next: f = frame_from_traceback(tb)
tb = tb.tb_next
f = tb.tb_frame
else: else:
f = inspect.currentframe() f = inspect.currentframe()
else: else:
......
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