You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
walk_tb (which rich's Traceback uses to zap through the callstack at exception time) - but also
walk_stack, where one can iterate over sys._getframe().f_back.f_back, i.e. over a frame.
It would be imho nice, if one could pass that walker generator function as an optional argument - then we could also print normal call stacks - i.e. outside of exceptions.
Right now one has to monkey patch rich to get to sth like that:
Done via a hack like this:
importtracebackastbdefmy_frames_walker(tb_or_frame):
# return python's walk_tb for rich, except when we are passed a frameifhasattr(tb_or_frame, 'f_back'):
returnreversed(tb.walk_stack(tb_or_frame))
else:
returntb.walk_tb(tb_or_frame)
rich.traceback.walk_tb=my_frames_walker
(...)
and use like this
classStackTrace(Exception):
passdefprint_frames(frame):
# fake an exception to make rich happy:si= [StackTrace, StackTrace(''), frame]
console.print(Traceback.from_exception(*si, show_locals=True))
Alternative, provide a print_frames, accepting an iterable over frames, where one could also filter (?)
reacted with thumbs up emoji reacted with thumbs down emoji reacted with laugh emoji reacted with hooray emoji reacted with confused emoji reacted with heart emoji reacted with rocket emoji reacted with eyes emoji
Uh oh!
There was an error while loading. Please reload this page.
Uh oh!
There was an error while loading. Please reload this page.
-
Hi, python's
traceback
offerswalk_tb
(which rich's Traceback uses to zap through the callstack at exception time) - but alsowalk_stack
, where one can iterate oversys._getframe().f_back.f_back
, i.e. over a frame.It would be imho nice, if one could pass that walker generator function as an optional argument - then we could also print normal call stacks - i.e. outside of exceptions.
Right now one has to monkey patch rich to get to sth like that:
Done via a hack like this:
and use like this
Alternative, provide a
print_frames
, accepting an iterable over frames, where one could also filter (?)Beta Was this translation helpful? Give feedback.
All reactions