Message364391
Currently ast.dump() in multiline mode (see issue37995) appends closing parenthesis to the end of the line:
>>> import ast
>>> node = ast.parse('spam(eggs, "and cheese")')
>>> print(ast.dump(node, indent=3))
Module(
body=[
Expr(
value=Call(
func=Name(id='spam', ctx=Load()),
args=[
Name(id='eggs', ctx=Load()),
Constant(value='and cheese')],
keywords=[]))],
type_ignores=[])
It uses vertical space more efficiently (which is especially important on Windows console).
But I got a feedback about output closing parenthesis on separate lines (msg363783):
Module(
body=[
Expr(
value=Call(
func=Name(id='spam', ctx=Load()),
args=[
Name(id='eggs', ctx=Load()),
Constant(value='and cheese')
],
keywords=[]
)
)
],
type_ignores=[]
)
It looks more "balanced", but less vertical space efficient. It adds almost 300 lines to 57 examples in Doc/library/ast.rst. And after omitting optional list arguments like keywords=[] and type_ignores=[] (see issue39981) the stairs of parenthesis will look even longer.
The proposed PR changes the output of ast.dump() by moving closing parenthesis on separate lines. I am still not sure what output is better. |
|
Date |
User |
Action |
Args |
2020-03-17 08:06:12 | serhiy.storchaka | set | recipients:
+ serhiy.storchaka, rhettinger, terry.reedy, benjamin.peterson, pablogsal |
2020-03-17 08:06:12 | serhiy.storchaka | set | messageid: <1584432372.22.0.904187572723.issue39989@roundup.psfhosted.org> |
2020-03-17 08:06:12 | serhiy.storchaka | link | issue39989 messages |
2020-03-17 08:06:12 | serhiy.storchaka | create | |
|