berkerpeksag / astor

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

adds extra backslash #172

Open ikamensh opened 4 years ago

ikamensh commented 4 years ago

having a " character before a new line results in restored string having \" in it. Example:

import ast
import astor
length, quotes = 15, 20
text = """
# This is an example configuration
# Hash lines are comments

[flake8]
inline-quotes="Hello"
"""

with open(__file__) as f:
    txt = f.read()

tree = ast.parse(txt)
restored = astor.to_source(tree)
print(restored)

Output:

/Users/username/.pyenv/versions/3.7.3/bin/python /Users/username/Library/Preferences/PyCharm2019.2/scratches/bridges.py
import ast
import astor
length, quotes = 15, 20
text = """
# This is an example configuration
# Hash lines are comments"

[flake8]
inline-quotes="Hello\"
"""
with open(__file__) as f:
    txt = f.read()
tree = ast.parse(txt)
restored = astor.to_source(tree)
print(restored)