Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
webknjaz opened this issue Sep 25, 2019 · 2 comments

Comments

@webknjaz
Copy link
Contributor

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.

webknjaz added a commit to webknjaz/redbaron that referenced this issue Sep 25, 2019
@webknjaz
Copy link
Contributor Author

Reproducer: #191

@webknjaz
Copy link
Contributor Author

Oh, and I originally got hit this by doing fst[23:24] = [new, nodes, list], not insert_after(), but this one looks simpler for the purposes of the demo.

webknjaz added a commit to webknjaz/collection_migration that referenced this issue Jan 7, 2020
webknjaz added a commit to ansible-community/collection_migration that referenced this issue Jan 16, 2020
webknjaz added a commit to webknjaz/collection_migration that referenced this issue Jan 16, 2020
webknjaz added a commit to webknjaz/collection_migration that referenced this issue Jan 16, 2020
It's a workaround for PyCQA/redbaron#190

Also:
* Ensure there's LF @ rewritten module EOL
webknjaz added a commit to webknjaz/collection_migration that referenced this issue Jan 16, 2020
It's a workaround for PyCQA/redbaron#190

Also:
* Ensure there's LF @ rewritten module EOL
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

1 participant