Open bombs-kim opened 3 years ago
I have an similar error.
from ast import parse
from astor import to_source
s4 = '''str_1 = f"""["{'", "'.join(lst_item)}"]"""'''
parse(to_source(parse(s4)))
SyntaxError: f-string expression part cannot include a backslash
from ast import parse
from astor import to_source
s4 = '''str_1 = f"""["{'", "'.join(lst_item)}"]"""'''
to_source(parse(s4))
'str_1 = f\'["{\\'", "\\'.join(lst_item)}"]\'\n'
But expected
'str_1= f"""["{'", "'.join(lst_item)}"]"""\n'
I found a case where ast.to_source does not return a valid python code. Here is an example.
Also, is there a way that I can get around this before this bug is fixed? I have many s2 type source code snippets that should be parsed to an ast, be tweaked a little, and be reconstructed back to a snippet.