-
-
Notifications
You must be signed in to change notification settings - Fork 30.9k
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
Improve repr()
of AST nodes
#116022
Comments
This is something that would be useful for me as well since I also sometimes poke around the AST 😄 Were you planning to implement this yourself or do you think I could give it a try? Looking at the code, it'll probably have to be implemented in C since that's where the base AST type is defined. |
I will do it eventually if no one else gets to it but haven't started yet. You're welcome to start working on it! This might need changes to |
Co-authored-by: AN Long <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
Co-authored-by: AN Long <[email protected]> Co-authored-by: Jelle Zijlstra <[email protected]> Co-authored-by: Alex Waygood <[email protected]> Co-authored-by: Bénédikt Tran <[email protected]>
Feature or enhancement
Proposal:
I often use
ast.parse
in the terminal to explore what the AST looks like:But I have to remember to use
ast.dump()
to get useful output:It would be nice if the default repr() of AST nodes was more like the output of
ast.dump()
, so it's easier to see at a glance how it works.One concern would be around the size of the output:
As a middle ground, we could limit the depth of the AST provided in the repr(), e.g. to 2 levels, and also the number of list elements provided.
The repr() of a module's AST might then look something like:
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
Links to previous discussion of this feature:
No response
Linked PRs
repr()
of AST nodes #117046The text was updated successfully, but these errors were encountered: