Skip to content

[BUG] dumps() emits an extra EOL in the EOF after inserting a node if source code ends with if-block #190

@webknjaz

Description

@webknjaz

So basically when I parse src = '\nimport i1\nimport i2\n\nif True:\n pass\n and dump immediately, it emits the same result as the source.

But if I parse that and insert a root-level node, it adds an extra \n in the very end.

fst = RedBaron(src)
imp1, imp2 = fst.find_all('import')
imp2.insert_after(imp1)
fst.dumps()

The above returns '\nimport i1\nimport i2\nimport i1\n\nif True:\n pass\n\n'. (Note double LF in the end)

I could only reproduce this with an if-block (if-else too), but other nested constructs (like def or with-block) are not affected by this bug.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions