You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
After #105858, it would be nice if ast.dump() also didn't output optional fields that are set to None or an empty string, so that its output is more concise. This should make it easier to understand the structure of large ASTs where most fields are missing.
Has this already been discussed elsewhere?
This is a minor feature, which does not need previous discussion elsewhere
I think this is fine; it matches the constructor and it is analogous to how list(), dict(), and tuple() work. However, I thought I'd flag it in case others think these nodes should be special-cased.
Why does the repr for ast.Dict() not include ctx=Load() in it, when the reprs for Tuple and List do?
I see that the same thing happens on Python 3.12, so this definitely isn't a regression... but I'd still be curious if anybody knows why this is different for the different nodes!
Activity
pythongh-116023: Add `show_empty=True` to `ast.dump`
gh-116023: Add `show_empty=False` to `ast.dump` (#116037)
JelleZijlstra commentedon Apr 28, 2024
I noticed that the representation on an empty
ast.Tuplechanged fromTuple(elts=[], ctx=Load())toTuple(ctx=Load()), and same for lists and dicts:I think this is fine; it matches the constructor and it is analogous to how
list(),dict(), andtuple()work. However, I thought I'd flag it in case others think these nodes should be special-cased.AlexWaygood commentedon Apr 28, 2024
Why does the repr for
ast.Dict()not includectx=Load()in it, when the reprs forTupleandListdo?AlexWaygood commentedon Apr 28, 2024
I see that the same thing happens on Python 3.12, so this definitely isn't a regression... but I'd still be curious if anybody knows why this is different for the different nodes!
JelleZijlstra commentedon Apr 28, 2024
It's because
ast.Dictcan't appear on the left-hand side of an assignment.I was thinking of whether we'd also want to default the
ctxparameter of these and other nodes toLoad(), but that's for another day.