cknd / stackprinter

Debugging-friendly exceptions for Python
MIT License
1.28k stars 37 forks source link

Inspect the AST instead of iterating through the tokenized source #22

Closed cknd closed 2 years ago

cknd commented 5 years ago

Currently, to find out where in the code which variable names occur, I traverse the code token-by-token and apply a sort of ad hoc stack machine that detects stuff like the beginning of function definitions, dot attributes etc. This is clearly nuts, and purely a path effect (= it's how ipython's ultratb does it, and then my scope expanded and here we are). https://github.com/cknd/stackprinter/blob/master/stackprinter/source_inspection.py

This approach works for now, but it has hit its limits. For example, I'd like to ignore the left-hand side of named arguments in function calls.

Goals:

alexmojaki commented 5 years ago

I'm working on a library of the kind that was discussed in better-exceptions and IPython and planning on using it here. It's entirely AST based and satisfies these requirements. It uses https://github.com/gristlabs/asttokens for the second point and https://github.com/alexmojaki/executing for some extra functionality.

cknd commented 5 years ago

sounds very promising!

alexmojaki commented 5 years ago

If you're interested in a sneak peek or following progress, I've just created the repo here: https://github.com/alexmojaki/stack_data

Still lots of work to do though.

cknd commented 5 years ago

👀

cknd commented 2 years ago

the solution is #52