-
-
Notifications
You must be signed in to change notification settings - Fork 1.9k
Closed
Labels
enhancementNew feature or requestNew feature or request
Description
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:
- 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.
willmcgugan, nmstoker and CamTosh
Metadata
Metadata
Assignees
Labels
enhancementNew feature or requestNew feature or request