-
-
Notifications
You must be signed in to change notification settings - Fork 34.4k
Improve repr() of AST nodes #116022
Copy link
Copy link
Closed
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-parsertype-featureA feature request or enhancementA feature request or enhancement
Metadata
Metadata
Assignees
Labels
stdlibStandard Library Python modules in the Lib/ directoryStandard Library Python modules in the Lib/ directorytopic-parsertype-featureA feature request or enhancementA feature request or enhancement
Feature or enhancement
Proposal:
I often use
ast.parsein 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 #117046