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

lines_before_imports adds additional new lines #1854

Closed
robsdedude opened this issue Nov 22, 2021 · 1 comment · Fixed by #1861
Closed

lines_before_imports adds additional new lines #1854

robsdedude opened this issue Nov 22, 2021 · 1 comment · Fixed by #1861

Comments

@robsdedude
Copy link

robsdedude commented Nov 22, 2021

Here is a minimal example (or at least as small as I could get it) tested with version 5.10.1:

import isort

str_in = """# Some header, e.g. copyright 

from foo import bar


def main():
    ...
"""

str_out = isort.code(
    str_in,
    lines_before_imports=1
)
print("In:")
print(str_in)
print("-" * 79)
print("Out:")
print(str_out)

This yields the following:

In:
# Some header, e.g. copyright 

from foo import bar


def main():
    ...

-------------------------------------------------------------------------------
Out:
# Some header, e.g. copyright 


from foo import bar


def main():
    ...

So instead of making sure that there is one blank line above the import, isort adds 1 extra line at the top of the imports. This breaks similarly with lines_before_imports=2 and so on.

@anirudnits
Copy link
Collaborator

Hey @robsdedude, thanks for raising this. I'll try and replicate the issue and initially add a test case.

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

Successfully merging a pull request may close this issue.

2 participants