berkerpeksag / astor

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

Transforming multi-line strings :-1: #93

Closed alexander-alvarez closed 6 years ago

alexander-alvarez commented 6 years ago

Running in Python 3.6.4

f"Hello " \
" {name}"

# printing the above yields
# "Hello {name}"

src dump

Module(body=[Expr(value=JoinedStr(values=[Str(s='Hello  {name}')]))])

dst dump:

Module(
    body=[
        Expr(
            value=JoinedStr(
                values=[Str(s='Hello  '), FormattedValue(value=Name(id='name'), conversion=-1, format_spec=None)]))])

Will investigate why this happens

alexander-alvarez commented 6 years ago

The problem is more general. I'm investigating failing test cases

alexander-alvarez commented 6 years ago

looks like this is a limitation of the ptyhon ast and in the python issue tracker they seemed to desire this. a multi-line string

"a" \
"b"

gets ast.parse-d as "ab" They recommend using a different parser... e.g. https://github.com/PyCQA/redbaron

Carrying on with my day