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
The AST docs need some love as they can be a bit obscure to someone new to the module. Improvements to be considered in this issue:
Document all available nodes (as of 3.8 and not deprecated ones). This helps to know what classes to consider when implementing methods for the visitors.
Add some short practical examples for the visitors: one to query an AST and another to modify it.
New changeset 114081f by Pablo Galindo in branch 'master': bpo-39199: Add descriptions of non-deprecated nodes to the AST module documentation (GH-17812) 114081f
The first one looks on first inspection "cleaner" but then I tried to look at a random closed bracket/parenthesis like the ones in
value=Constant(value=Ellipsis))])])],
and trying to guess where that closes and is confusing to say the least so I think I would prefer the second one as is less "dense".
Additionally, I was curious and I have asked several people with different examples and almost everyone prefers the second one, being
the only reason someone preferred the first the fact that "fits vertically in the screen and you need less scrolling to read it all".
Activity
pablogsal commentedon Jan 3, 2020
The AST docs need some love as they can be a bit obscure to someone new to the module. Improvements to be considered in this issue:
Document all available nodes (as of 3.8 and not deprecated ones). This helps to know what classes to consider when implementing methods for the visitors.
Add some short practical examples for the visitors: one to query an AST and another to modify it.
pablogsal commentedon Mar 2, 2020
New changeset 114081f by Pablo Galindo in branch 'master':
bpo-39199: Add descriptions of non-deprecated nodes to the AST module documentation (GH-17812)
114081f
serhiy-storchaka commentedon Mar 7, 2020
Would not be better to use mode='eval' for expression nodes?
>>> print(ast.dump(ast.parse('123', mode='eval'), indent=4)) Expression( body=Constant(value=123, kind=None))pablogsal commentedon Mar 7, 2020
Agreed! I will prepare a PR soon to simplify the expression examples.
pablogsal commentedon Mar 7, 2020
New changeset 02f64cb by Pablo Galindo in branch 'master':
bpo-39199: Use 'eval' mode for the examples with expression nodes (GH-18828)
02f64cb
serhiy-storchaka commentedon Mar 9, 2020
As you worked much with ast.dump(), what multi-line formatting do you prefer, the current
or with closing brackets on separate lines?
The latter make contain long stairs of closing brackets.
pablogsal commentedon Mar 9, 2020
The first one looks on first inspection "cleaner" but then I tried to look at a random closed bracket/parenthesis like the ones in
value=Constant(value=Ellipsis))])])],and trying to guess where that closes and is confusing to say the least so I think I would prefer the second one as is less "dense".
Additionally, I was curious and I have asked several people with different examples and almost everyone prefers the second one, being
the only reason someone preferred the first the fact that "fits vertically in the screen and you need less scrolling to read it all".