Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Closed
cknd opened this issue Aug 25, 2019 · 5 comments
Closed

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

cknd opened this issue Aug 25, 2019 · 5 comments

Comments

@cknd
Copy link
Owner

cknd commented Aug 25, 2019

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:

  • annotate in a piece of code where each variable name occurs, exactly like the current system, but with less of a home made rube goldberg machine behind it.
  • keep the ability to rerender the original code character by character as it appears in the source file (incl extra whitespaces, comment ascii art etc -- so people can visually recognize their code)
@alexmojaki
Copy link
Contributor

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
Copy link
Owner Author

cknd commented Aug 25, 2019

sounds very promising!

@alexmojaki
Copy link
Contributor

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
Copy link
Owner Author

cknd commented Aug 26, 2019

👀

@cknd
Copy link
Owner Author

cknd commented Apr 2, 2022

the solution is #52

@cknd cknd closed this as completed Apr 2, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants