[issue39989] Output closing parenthesis in ast.dump() on separate line
Serhiy Storchaka
report at bugs.python.org
Tue Mar 17 04:06:12 EDT 2020
New submission from Serhiy Storchaka <storchaka+cpython at gmail.com>:
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.
----------
components: Library (Lib)
messages: 364391
nosy: benjamin.peterson, pablogsal, rhettinger, serhiy.storchaka, terry.reedy
priority: normal
severity: normal
status: open
title: Output closing parenthesis in ast.dump() on separate line
type: enhancement
versions: Python 3.9
_______________________________________
Python tracker <report at bugs.python.org>
<https://bugs.python.org/issue39989>
_______________________________________
More information about the Python-bugs-list
mailing list