berkerpeksag / astor

Python AST read/write
https://pypi.org/project/astor/
BSD 3-Clause "New" or "Revised" License
803 stars 102 forks source link

parenthesis around expressions in a JoinedString #153

Closed ikamensh closed 4 years ago

ikamensh commented 5 years ago

Astor wraps expressions into parenthesis, also when this is completely redundant:

code = '''print(f"{var + 1:.2f}")'''

import ast
tree = ast.parse(code)
import astor
recovered = astor.to_source(tree)

print('original:   ',code)
print('astor:      ',recovered)

output:

original:    print(f"{var + 1:.2f}")
astor:       print(f'{(var + 1):.2f}')

Python: 3.6.8 astor: 0.8.0

isidentical commented 5 years ago

Just saw, preparing patch (sorry for delay).