astunparse icon indicating copy to clipboard operation
astunparse copied to clipboard

incorrect escaped string unparse

Open scgbckbone opened this issue 5 years ago • 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

scgbckbone avatar Jul 29 '20 07:07 scgbckbone

same issue

PietroPasotti avatar Sep 13 '24 12:09 PietroPasotti