[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-22 Thread Anthony Sottile


Anthony Sottile  added the comment:

fwiw, astpretty's output looks like the black output: 
https://github.com/asottile/astpretty

>>> astpretty.pprint(ast.parse('if x == y: y += 4').body[0])
If(
lineno=1,
col_offset=0,
test=Compare(
lineno=1,
col_offset=3,
left=Name(lineno=1, col_offset=3, id='x', ctx=Load()),
ops=[Eq()],
comparators=[Name(lineno=1, col_offset=8, id='y', ctx=Load())],
),
body=[
AugAssign(
lineno=1,
col_offset=11,
target=Name(lineno=1, col_offset=11, id='y', ctx=Store()),
op=Add(),
value=Num(lineno=1, col_offset=16, n=4),
),
],
orelse=[],
)

--
nosy: +Anthony Sottile

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-17 Thread Terry J. Reedy


Terry J. Reedy  added the comment:

The current output looks like Python code.  The proposed revision looks more 
like C, and I find the example above less readable with the prominence given to 
what is close to noise.  The difference is part of the reason I left C for 
Python over 2 decades ago.  Please make the alternative an option.  The 
preferred form depends on the person and possibly the AST.  (The example in 
Pablo's message is quite different.)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-17 Thread Mark Dickinson


Mark Dickinson  added the comment:

Ah yes; looking at the `black` output, there's also an opportunity for an 
exciting discussion about trailing commas here :-)

--

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-17 Thread Eric V. Smith


Eric V. Smith  added the comment:

For what it's worth (which might not be much), here is what black produces:

Module(
body=[
Expr(
value=Call(
func=Name(id="spam", ctx=Load()),
args=[Name(id="eggs", ctx=Load()), Constant(value="and 
cheese")],
keywords=[],
)
)
],
type_ignores=[],
)

I agree with Mark: it's all probably personal preference, and I'd be okay 
either way.

--
nosy: +eric.smith

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-17 Thread Mark Dickinson


Mark Dickinson  added the comment:

This feels like something that's very much down to personal preference. 

I also prefer the closing "]" and ")" characters on their own lines, but I'd be 
happy with an argument to ast.dump giving me that option.

--
nosy: +mark.dickinson

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-17 Thread Serhiy Storchaka


Change by Serhiy Storchaka :


--
keywords: +patch
pull_requests: +18390
stage:  -> patch review
pull_request: https://github.com/python/cpython/pull/19039

___
Python tracker 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com



[issue39989] Output closing parenthesis in ast.dump() on separate line

2020-03-17 Thread Serhiy Storchaka


New submission from Serhiy Storchaka :

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 

___
___
Python-bugs-list mailing list
Unsubscribe: 
https://mail.python.org/mailman/options/python-bugs-list/archive%40mail-archive.com