This issue is for tracking possible places where we could generate better code on ast.unparse (better as in more closely to what people are actually writing than our naive implementation).
Examples;
>>> import ast
>>> ast.unparse(ast.parse('a, b, c = [1,2,3]'))
'(a, b, c) = [1, 2, 3]'
could be
>>> ast.unparse(ast.parse('a, b, c = [1,2,3]'))
'a, b, c = [1, 2, 3]'
OR
>>> print(ast.unparse(ast.parse('if value := d.get("something"): print(value)')))
if (value := d.get('something')):
print(value)
could be
>>> print(ast.unparse(ast.parse('if value := d.get("something"): print(value)')))
if value := d.get('something'):
print(value)
We could even go further with the long line unpacking (which would definitely require some sort of clever algorithm for nested structures).
>>> source = '[\n' + '\tsomething,\n' * 20 + ']'
>>> print(source)
[
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
something,
]
>>> print(ast.unparse(ast.parse(source)))
[something, something, something, something, something, something, something, something, something, something, something, something, something, something, something, something, something, something, something, something]
|