simonpercivall/astunparse

incorrect escaped string unparse

scgbckbone opened this issue · 1 comments

create a file with following contents and name it target.py:

phys_vol_name = "test123"
raise RuntimeError(f'Can\'t find the volume group "{phys_vol_name}"')

then use this script to parse & unparse to create new file result.py

import ast
import astunparse

with open("target.py", "r") as f:
    res = astunparse.unparse(ast.parse(f.read()))

with open("result.py", "w") as ff:
    ff.write(res)

when you run result.py you get syntaxt error:

File "result.py", line 3
    raise RuntimeError(f"""Can't find the volume group "{phys_vol_name}"""")
                                                                           ^
SyntaxError: EOL while scanning string literal

same issue