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
Hi! I've recently created a few libraries that are helpful for extracting information from frames and tracebacks, and I think they could be very useful to rich.
executing can identify the exact AST node being executed by a frame in many cases. It's always disappointed me that Python only points to a line in each frame in tracebacks, especially when the expression/statement at fault spans many lines. Sometimes it can be really hard to interpret. Currently executing is used in IPython (in master, unreleased) to highlight the node, here's what it looks like:
executing can also infer a function __qualname__ from a code object, meaning your traceback can say lorem/ipsum.py in MyClass.__init__ at line 123 instead of just __init__, which is much more informative.
pure_eval can safely evaluate certain AST nodes without side effects, so that if the source for a frame contains expressions like self.foo and bar[key] their values can often be shown alongside plain variables.
stack_data collects data from tracebacks for the purpose of formatting and displaying them. It uses executing and pure_eval and also provides a lot of functionality of its own. I integratedstack_data into IPython which allowed removing a lot of flaky custom introspection code, fixing several bugs and making the code more maintainable.
For rich, I'm thinking you could use stack_data to:
Reduce the amount of code in the repo.
More intelligently select which lines of code to display, instead of just a fixed number lines before and after.
Display the values of local variables and other expressions for each frame in a nice table.
Highlight the node being executed.
Show the code qualname.
Handle repeated frames, especially when the user gets a RecursionError: maximum recursion depth exceeded. Right now it gets stuck for a while before producing a massive traceback.
What do you think? If you want to know more I suggest looking through the stack_data README to get an idea of what it can do and how to use it.
The text was updated successfully, but these errors were encountered:
That does look like it would make a very nice addition to Rich tracebacks. Thanks for letting me know, I'm going to go through your work and see what I can make use of.
Hi! I've recently created a few libraries that are helpful for extracting information from frames and tracebacks, and I think they could be very useful to rich.
executing
can identify the exact AST node being executed by a frame in many cases. It's always disappointed me that Python only points to a line in each frame in tracebacks, especially when the expression/statement at fault spans many lines. Sometimes it can be really hard to interpret. Currently executing is used in IPython (in master, unreleased) to highlight the node, here's what it looks like:executing
can also infer a function__qualname__
from a code object, meaning your traceback can saylorem/ipsum.py in MyClass.__init__ at line 123
instead of just__init__
, which is much more informative.pure_eval
can safely evaluate certain AST nodes without side effects, so that if the source for a frame contains expressions likeself.foo
andbar[key]
their values can often be shown alongside plain variables.stack_data
collects data from tracebacks for the purpose of formatting and displaying them. It usesexecuting
andpure_eval
and also provides a lot of functionality of its own. I integratedstack_data
into IPython which allowed removing a lot of flaky custom introspection code, fixing several bugs and making the code more maintainable.For rich, I'm thinking you could use stack_data to:
RecursionError: maximum recursion depth exceeded
. Right now it gets stuck for a while before producing a massive traceback.What do you think? If you want to know more I suggest looking through the stack_data README to get an idea of what it can do and how to use it.
The text was updated successfully, but these errors were encountered: